@@ -505,6 +505,7 @@ public <S extends T, R> R findBy(Specification<T> spec, Function<FetchableFluent
505
505
return doFindBy (spec , getDomainClass (), queryFunction );
506
506
}
507
507
508
+ @ SuppressWarnings ("unchecked" )
508
509
private <S extends T , R > R doFindBy (Specification <T > spec , Class <T > domainClass ,
509
510
Function <FetchableFluentQuery <S >, R > queryFunction ) {
510
511
@@ -594,6 +595,7 @@ public <S extends T> Page<S> findAll(Example<S> example, Pageable pageable) {
594
595
}
595
596
596
597
@ Override
598
+ @ SuppressWarnings ("unchecked" )
597
599
public <S extends T , R > R findBy (Example <S > example , Function <FetchableFluentQuery <S >, R > queryFunction ) {
598
600
599
601
Assert .notNull (example , EXAMPLE_MUST_NOT_BE_NULL );
@@ -616,7 +618,7 @@ public long count() {
616
618
}
617
619
618
620
@ Override
619
- public long count (@ Nullable Specification <T > spec ) {
621
+ public long count (Specification <T > spec ) {
620
622
return executeCountQuery (getCountQuery (spec , getDomainClass ()));
621
623
}
622
624
@@ -685,7 +687,7 @@ public void flush() {
685
687
* @deprecated use {@link #readPage(TypedQuery, Class, Pageable, Specification)} instead
686
688
*/
687
689
@ Deprecated
688
- protected Page <T > readPage (TypedQuery <T > query , Pageable pageable , @ Nullable Specification <T > spec ) {
690
+ protected Page <T > readPage (TypedQuery <T > query , Pageable pageable , Specification <T > spec ) {
689
691
return readPage (query , getDomainClass (), pageable , spec );
690
692
}
691
693
@@ -695,11 +697,13 @@ protected Page<T> readPage(TypedQuery<T> query, Pageable pageable, @Nullable Spe
695
697
*
696
698
* @param query must not be {@literal null}.
697
699
* @param domainClass must not be {@literal null}.
698
- * @param spec can be {@literal null}.
700
+ * @param spec must not be {@literal null}.
699
701
* @param pageable can be {@literal null}.
700
702
*/
701
703
protected <S extends T > Page <S > readPage (TypedQuery <S > query , final Class <S > domainClass , Pageable pageable ,
702
- @ Nullable Specification <S > spec ) {
704
+ Specification <S > spec ) {
705
+
706
+ Assert .notNull (spec , "Specification must not be null" );
703
707
704
708
if (pageable .isPaged ()) {
705
709
query .setFirstResult (PageableUtils .getOffsetAsInteger (pageable ));
@@ -713,22 +717,22 @@ protected <S extends T> Page<S> readPage(TypedQuery<S> query, final Class<S> dom
713
717
/**
714
718
* Creates a new {@link TypedQuery} from the given {@link Specification}.
715
719
*
716
- * @param spec can be {@literal null}.
720
+ * @param spec must not be {@literal null}.
717
721
* @param pageable must not be {@literal null}.
718
722
*/
719
- protected TypedQuery <T > getQuery (@ Nullable Specification <T > spec , Pageable pageable ) {
723
+ protected TypedQuery <T > getQuery (Specification <T > spec , Pageable pageable ) {
720
724
721
725
return getQuery (spec , getDomainClass (), pageable .getSort ());
722
726
}
723
727
724
728
/**
725
729
* Creates a new {@link TypedQuery} from the given {@link Specification}.
726
730
*
727
- * @param spec can be {@literal null}.
731
+ * @param spec must not be {@literal null}.
728
732
* @param domainClass must not be {@literal null}.
729
733
* @param pageable must not be {@literal null}.
730
734
*/
731
- protected <S extends T > TypedQuery <S > getQuery (@ Nullable Specification <S > spec , Class <S > domainClass ,
735
+ protected <S extends T > TypedQuery <S > getQuery (Specification <S > spec , Class <S > domainClass ,
732
736
Pageable pageable ) {
733
737
734
738
return getQuery (spec , domainClass , pageable .getSort ());
@@ -856,21 +860,23 @@ protected <S> Query getDelete(DeleteSpecification<S> spec, Class<S> domainClass)
856
860
/**
857
861
* Creates a new count query for the given {@link Specification}.
858
862
*
859
- * @param spec can be {@literal null}.
863
+ * @param spec must not be {@literal null}.
860
864
* @deprecated override {@link #getCountQuery(Specification, Class)} instead
861
865
*/
862
866
@ Deprecated
863
- protected TypedQuery <Long > getCountQuery (@ Nullable Specification <T > spec ) {
867
+ protected TypedQuery <Long > getCountQuery (Specification <T > spec ) {
864
868
return getCountQuery (spec , getDomainClass ());
865
869
}
866
870
867
871
/**
868
872
* Creates a new count query for the given {@link Specification}.
869
873
*
870
- * @param spec can be {@literal null}.
874
+ * @param spec must not be {@literal null}.
871
875
* @param domainClass must not be {@literal null}.
872
876
*/
873
- protected <S extends T > TypedQuery <Long > getCountQuery (@ Nullable Specification <S > spec , Class <S > domainClass ) {
877
+ protected <S extends T > TypedQuery <Long > getCountQuery (Specification <S > spec , Class <S > domainClass ) {
878
+
879
+ Assert .notNull (spec , "Specification must not be null" );
874
880
875
881
CriteriaBuilder builder = entityManager .getCriteriaBuilder ();
876
882
CriteriaQuery <Long > query = builder .createQuery (Long .class );
@@ -1020,7 +1026,7 @@ private Map<String, Object> getHints() {
1020
1026
private void applyComment (CrudMethodMetadata metadata , BiConsumer <String , Object > consumer ) {
1021
1027
1022
1028
if (metadata .getComment () != null && provider .getCommentHintKey () != null ) {
1023
- consumer .accept (provider .getCommentHintKey (), provider .getCommentHintValue (this . metadata .getComment ()));
1029
+ consumer .accept (provider .getCommentHintKey (), provider .getCommentHintValue (metadata .getComment ()));
1024
1030
}
1025
1031
}
1026
1032
0 commit comments