Skip to content

Commit f50d356

Browse files
committed
Polishing.
Reinstate original Javadoc, add note about nullability. Fix contract annotation, refine tests. See #3992 Original pull request: #3998
1 parent a1fbb5a commit f50d356

File tree

3 files changed

+17
-18
lines changed

3 files changed

+17
-18
lines changed

spring-data-jpa/src/main/java/org/springframework/data/jpa/domain/Specification.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,33 +65,35 @@ static <T> Specification<T> unrestricted() {
6565
}
6666

6767
/**
68-
* Simple static factory method to add some syntactic sugar translating {@link PredicateSpecification} to
69-
* {@link Specification}.
68+
* Simple static factory method to add some syntactic sugar around a {@link Specification}.
7069
*
70+
* @implNote does not accept {@literal null} values since 4.0, use {@link #unrestricted()} instead of passing
71+
* {@literal null} values.
7172
* @param <T> the type of the {@link Root} the resulting {@literal Specification} operates on.
72-
* @param spec the {@link PredicateSpecification} to wrap.
73+
* @param spec can be {@literal null}.
7374
* @return guaranteed to be not {@literal null}.
75+
* @since 2.0
7476
*/
75-
static <T> Specification<T> where(PredicateSpecification<T> spec) {
77+
static <T> Specification<T> where(Specification<T> spec) {
7678

77-
Assert.notNull(spec, "PredicateSpecification must not be null");
79+
Assert.notNull(spec, "Specification must not be null");
7880

79-
return (root, update, criteriaBuilder) -> spec.toPredicate(root, criteriaBuilder);
81+
return spec;
8082
}
8183

8284
/**
83-
* Creates a {@link Specification} from the given {@link Specification}. This is a factory method for fluent composition.
85+
* Simple static factory method to add some syntactic sugar translating {@link PredicateSpecification} to
86+
* {@link Specification}.
8487
*
8588
* @param <T> the type of the {@link Root} the resulting {@literal Specification} operates on.
86-
* @param spec must not be {@literal null}.
87-
* @return the given specification.
88-
* @since 4.1
89+
* @param spec the {@link PredicateSpecification} to wrap.
90+
* @return guaranteed to be not {@literal null}.
8991
*/
90-
static <T> Specification<T> where(Specification<T> spec) {
92+
static <T> Specification<T> where(PredicateSpecification<T> spec) {
9193

92-
Assert.notNull(spec, "Specification must not be null");
94+
Assert.notNull(spec, "PredicateSpecification must not be null");
9395

94-
return spec;
96+
return (root, update, criteriaBuilder) -> spec.toPredicate(root, criteriaBuilder);
9597
}
9698

9799
/**

spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/ParameterBinding.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ public JpqlQueryTemplates getTemplates() {
291291

292292

293293
@SuppressWarnings("unchecked")
294-
@Contract("false, _ -> param2; _, null -> null; true, !null -> new)")
294+
@Contract("false, _ -> param2; _, null -> null; true, !null -> new")
295295
private @Nullable Collection<?> potentiallyIgnoreCase(boolean ignoreCase, @Nullable Collection<?> collection) {
296296

297297
if (!ignoreCase || CollectionUtils.isEmpty(collection)) {

spring-data-jpa/src/test/java/org/springframework/data/jpa/domain/SpecificationUnitTests.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,7 @@ void whereWithSpecificationSupportsFluentComposition() {
162162

163163
@Test // GH-3992
164164
void whereWithNullSpecificationThrowsException() {
165-
166-
assertThatThrownBy(() -> Specification.where((Specification<Object>) null))
167-
.isInstanceOf(IllegalArgumentException.class)
168-
.hasMessage("Specification must not be null");
165+
assertThatIllegalArgumentException().isThrownBy(() -> Specification.where((Specification<Object>) null));
169166
}
170167

171168
static class SerializableSpecification implements Serializable, Specification<Object> {

0 commit comments

Comments
 (0)