@@ -498,6 +498,7 @@ public <S extends T, R> R findBy(Specification<T> spec, Function<FetchableFluent
498
498
return doFindBy (spec , getDomainClass (), queryFunction );
499
499
}
500
500
501
+ @ SuppressWarnings ("unchecked" )
501
502
private <S extends T , R > R doFindBy (Specification <T > spec , Class <T > domainClass ,
502
503
Function <FetchableFluentQuery <S >, R > queryFunction ) {
503
504
@@ -586,6 +587,7 @@ public <S extends T> Page<S> findAll(Example<S> example, Pageable pageable) {
586
587
}
587
588
588
589
@ Override
590
+ @ SuppressWarnings ("unchecked" )
589
591
public <S extends T , R > R findBy (Example <S > example , Function <FetchableFluentQuery <S >, R > queryFunction ) {
590
592
591
593
Assert .notNull (example , EXAMPLE_MUST_NOT_BE_NULL );
@@ -608,7 +610,7 @@ public long count() {
608
610
}
609
611
610
612
@ Override
611
- public long count (@ Nullable Specification <T > spec ) {
613
+ public long count (Specification <T > spec ) {
612
614
return executeCountQuery (getCountQuery (spec , getDomainClass ()));
613
615
}
614
616
@@ -677,7 +679,7 @@ public void flush() {
677
679
* @deprecated use {@link #readPage(TypedQuery, Class, Pageable, Specification)} instead
678
680
*/
679
681
@ Deprecated
680
- protected Page <T > readPage (TypedQuery <T > query , Pageable pageable , @ Nullable Specification <T > spec ) {
682
+ protected Page <T > readPage (TypedQuery <T > query , Pageable pageable , Specification <T > spec ) {
681
683
return readPage (query , getDomainClass (), pageable , spec );
682
684
}
683
685
@@ -687,11 +689,13 @@ protected Page<T> readPage(TypedQuery<T> query, Pageable pageable, @Nullable Spe
687
689
*
688
690
* @param query must not be {@literal null}.
689
691
* @param domainClass must not be {@literal null}.
690
- * @param spec can be {@literal null}.
692
+ * @param spec must not be {@literal null}.
691
693
* @param pageable can be {@literal null}.
692
694
*/
693
695
protected <S extends T > Page <S > readPage (TypedQuery <S > query , final Class <S > domainClass , Pageable pageable ,
694
- @ Nullable Specification <S > spec ) {
696
+ Specification <S > spec ) {
697
+
698
+ Assert .notNull (spec , "Specification must not be null" );
695
699
696
700
if (pageable .isPaged ()) {
697
701
query .setFirstResult (PageableUtils .getOffsetAsInteger (pageable ));
@@ -705,22 +709,22 @@ protected <S extends T> Page<S> readPage(TypedQuery<S> query, final Class<S> dom
705
709
/**
706
710
* Creates a new {@link TypedQuery} from the given {@link Specification}.
707
711
*
708
- * @param spec can be {@literal null}.
712
+ * @param spec must not be {@literal null}.
709
713
* @param pageable must not be {@literal null}.
710
714
*/
711
- protected TypedQuery <T > getQuery (@ Nullable Specification <T > spec , Pageable pageable ) {
715
+ protected TypedQuery <T > getQuery (Specification <T > spec , Pageable pageable ) {
712
716
713
717
return getQuery (spec , getDomainClass (), pageable .getSort ());
714
718
}
715
719
716
720
/**
717
721
* Creates a new {@link TypedQuery} from the given {@link Specification}.
718
722
*
719
- * @param spec can be {@literal null}.
723
+ * @param spec must not be {@literal null}.
720
724
* @param domainClass must not be {@literal null}.
721
725
* @param pageable must not be {@literal null}.
722
726
*/
723
- protected <S extends T > TypedQuery <S > getQuery (@ Nullable Specification <S > spec , Class <S > domainClass ,
727
+ protected <S extends T > TypedQuery <S > getQuery (Specification <S > spec , Class <S > domainClass ,
724
728
Pageable pageable ) {
725
729
726
730
return getQuery (spec , domainClass , pageable .getSort ());
@@ -799,21 +803,23 @@ protected <S> Query getDelete(DeleteSpecification<S> spec, Class<S> domainClass)
799
803
/**
800
804
* Creates a new count query for the given {@link Specification}.
801
805
*
802
- * @param spec can be {@literal null}.
806
+ * @param spec must not be {@literal null}.
803
807
* @deprecated override {@link #getCountQuery(Specification, Class)} instead
804
808
*/
805
809
@ Deprecated
806
- protected TypedQuery <Long > getCountQuery (@ Nullable Specification <T > spec ) {
810
+ protected TypedQuery <Long > getCountQuery (Specification <T > spec ) {
807
811
return getCountQuery (spec , getDomainClass ());
808
812
}
809
813
810
814
/**
811
815
* Creates a new count query for the given {@link Specification}.
812
816
*
813
- * @param spec can be {@literal null}.
817
+ * @param spec must not be {@literal null}.
814
818
* @param domainClass must not be {@literal null}.
815
819
*/
816
- protected <S extends T > TypedQuery <Long > getCountQuery (@ Nullable Specification <S > spec , Class <S > domainClass ) {
820
+ protected <S extends T > TypedQuery <Long > getCountQuery (Specification <S > spec , Class <S > domainClass ) {
821
+
822
+ Assert .notNull (spec , "Specification must not be null" );
817
823
818
824
CriteriaBuilder builder = entityManager .getCriteriaBuilder ();
819
825
CriteriaQuery <Long > query = builder .createQuery (Long .class );
@@ -963,7 +969,7 @@ private Map<String, Object> getHints() {
963
969
private void applyComment (CrudMethodMetadata metadata , BiConsumer <String , Object > consumer ) {
964
970
965
971
if (metadata .getComment () != null && provider .getCommentHintKey () != null ) {
966
- consumer .accept (provider .getCommentHintKey (), provider .getCommentHintValue (this . metadata .getComment ()));
972
+ consumer .accept (provider .getCommentHintKey (), provider .getCommentHintValue (metadata .getComment ()));
967
973
}
968
974
}
969
975
0 commit comments