Skip to content

Commit af9dd61

Browse files
committed
DATACMNS-1726 - Polishing of nullability after Lombok removal.
Reviewed visibility modifiers manually introduced constructors previously provided by Lombok. Also some nullability constraints have been accidentally changed by that.
1 parent 5876bd2 commit af9dd61

10 files changed

+60
-33
lines changed

src/main/java/org/springframework/data/util/KotlinReflectionUtils.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,10 @@ static boolean isNullable(MethodParameter parameter) {
155155
}
156156

157157
private static boolean isLast(MethodParameter parameter) {
158-
return parameter.getParameterIndex() == parameter.getMethod().getParameterCount() - 1;
158+
159+
Method method = parameter.getMethod();
160+
161+
return method != null && parameter.getParameterIndex() == method.getParameterCount() - 1;
159162
}
160163

161164
/**

src/main/java/org/springframework/data/util/Lazy.java

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,29 @@ public class Lazy<T> implements Supplier<T> {
3838

3939
private final Supplier<? extends T> supplier;
4040

41-
private @Nullable T value = null;
42-
private boolean resolved = false;
41+
private @Nullable T value;
42+
private boolean resolved;
4343

44+
/**
45+
* Creates a new {@link Lazy} instance for the given supplier.
46+
*
47+
* @param supplier
48+
* @deprecated prefer {@link Lazy#of(Supplier)}, to be turned private in 2.5.
49+
*/
50+
@Deprecated
4451
public Lazy(Supplier<? extends T> supplier) {
45-
this.supplier = supplier;
52+
this(supplier, null, false);
4653
}
4754

48-
private Lazy(Supplier<? extends T> supplier, T value, boolean resolved) {
55+
/**
56+
* Creates a new {@link Lazy} for the given {@link Supplier}, value and whether it has been resolved or not.
57+
*
58+
* @param supplier must not be {@literal null}.
59+
* @param value can be {@literal null}.
60+
* @param resolved whether the value handed into the constructor represents a resolved value.
61+
*/
62+
private Lazy(Supplier<? extends T> supplier, @Nullable T value, boolean resolved) {
63+
4964
this.supplier = supplier;
5065
this.value = value;
5166
this.resolved = resolved;
@@ -226,7 +241,7 @@ public T getNullable() {
226241
* @see java.lang.Object#equals(java.lang.Object)
227242
*/
228243
@Override
229-
public boolean equals(Object o) {
244+
public boolean equals(@Nullable Object o) {
230245

231246
if (this == o) {
232247
return true;
@@ -255,9 +270,12 @@ public boolean equals(Object o) {
255270
*/
256271
@Override
257272
public int hashCode() {
273+
258274
int result = ObjectUtils.nullSafeHashCode(supplier);
275+
259276
result = 31 * result + ObjectUtils.nullSafeHashCode(value);
260277
result = 31 * result + (resolved ? 1 : 0);
278+
261279
return result;
262280
}
263281
}

src/main/java/org/springframework/data/util/MethodInvocationRecorder.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
import java.util.function.Function;
2626

2727
import org.aopalliance.intercept.MethodInvocation;
28-
2928
import org.springframework.aop.framework.ProxyFactory;
3029
import org.springframework.core.CollectionFactory;
3130
import org.springframework.core.ResolvableType;
31+
import org.springframework.lang.NonNull;
3232
import org.springframework.lang.Nullable;
3333
import org.springframework.util.Assert;
3434
import org.springframework.util.ObjectUtils;
@@ -170,9 +170,12 @@ private static final class InvocationInformation {
170170
private static final InvocationInformation NOT_INVOKED = new InvocationInformation(new Unrecorded(), null);
171171

172172
private final Recorded<?> recorded;
173-
@Nullable private final Method invokedMethod;
173+
private final @Nullable Method invokedMethod;
174+
175+
public InvocationInformation(Recorded<?> recorded, @Nullable Method invokedMethod) {
176+
177+
Assert.notNull(recorded, "Recorded must not be null!");
174178

175-
public InvocationInformation(Recorded<?> recorded, Method invokedMethod) {
176179
this.recorded = recorded;
177180
this.invokedMethod = invokedMethod;
178181
}
@@ -220,7 +223,7 @@ public Method getInvokedMethod() {
220223
* @see java.lang.Object#equals(java.lang.Object)
221224
*/
222225
@Override
223-
public boolean equals(Object o) {
226+
public boolean equals(@Nullable Object o) {
224227

225228
if (this == o) {
226229
return true;
@@ -245,8 +248,11 @@ public boolean equals(Object o) {
245248
*/
246249
@Override
247250
public int hashCode() {
251+
248252
int result = ObjectUtils.nullSafeHashCode(recorded);
253+
249254
result = 31 * result + ObjectUtils.nullSafeHashCode(invokedMethod);
255+
250256
return result;
251257
}
252258

@@ -275,7 +281,7 @@ private enum DefaultPropertyNameDetectionStrategy implements PropertyNameDetecti
275281
* (non-Javadoc)
276282
* @see org.springframework.hateoas.core.Recorder.PropertyNameDetectionStrategy#getPropertyName(java.lang.reflect.Method)
277283
*/
278-
284+
@NonNull
279285
@Override
280286
public String getPropertyName(Method method) {
281287
return getPropertyName(method.getReturnType(), method.getName());
@@ -299,7 +305,8 @@ public static class Recorded<T> {
299305
private final @Nullable T currentInstance;
300306
private final @Nullable MethodInvocationRecorder recorder;
301307

302-
public Recorded(T currentInstance, MethodInvocationRecorder recorder) {
308+
Recorded(@Nullable T currentInstance, @Nullable MethodInvocationRecorder recorder) {
309+
303310
this.currentInstance = currentInstance;
304311
this.recorder = recorder;
305312
}
@@ -367,6 +374,7 @@ public <S> Recorded<S> record(ToMapConverter<T, S> converter) {
367374
*/
368375
@Override
369376
public String toString() {
377+
370378
return "MethodInvocationRecorder.Recorded(currentInstance=" + this.currentInstance + ", recorder=" + this.recorder
371379
+ ")";
372380
}
@@ -378,7 +386,6 @@ public interface ToMapConverter<T, S> extends Function<T, Map<?, S>> {}
378386

379387
static class Unrecorded extends Recorded<Object> {
380388

381-
@SuppressWarnings("null")
382389
private Unrecorded() {
383390
super(null, null);
384391
}

src/main/java/org/springframework/data/util/Pair.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.stream.Collectors;
2121
import java.util.stream.Stream;
2222

23+
import org.springframework.lang.Nullable;
2324
import org.springframework.util.Assert;
2425
import org.springframework.util.ObjectUtils;
2526

@@ -90,7 +91,7 @@ public T getSecond() {
9091
* @see java.lang.Object#equals(java.lang.Object)
9192
*/
9293
@Override
93-
public boolean equals(Object o) {
94+
public boolean equals(@Nullable Object o) {
9495

9596
if (this == o) {
9697
return true;

src/main/java/org/springframework/data/util/ParameterTypes.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.stream.Collectors;
2727

2828
import org.springframework.core.convert.TypeDescriptor;
29+
import org.springframework.lang.Nullable;
2930
import org.springframework.util.Assert;
3031
import org.springframework.util.ConcurrentReferenceHashMap;
3132
import org.springframework.util.ObjectUtils;
@@ -282,14 +283,18 @@ private TypeDescriptor getTail() {
282283
* @see java.lang.Object#equals(java.lang.Object)
283284
*/
284285
@Override
285-
public boolean equals(Object o) {
286+
public boolean equals(@Nullable Object o) {
287+
286288
if (this == o) {
287289
return true;
288290
}
291+
289292
if (!(o instanceof ParameterTypes)) {
290293
return false;
291294
}
295+
292296
ParameterTypes that = (ParameterTypes) o;
297+
293298
return ObjectUtils.nullSafeEquals(types, that.types);
294299
}
295300

@@ -348,7 +353,7 @@ protected Optional<ParameterTypes> withLastVarArgs() {
348353
* @see org.springframework.data.util.ParentTypeAwareTypeInformation#equals(java.lang.Object)
349354
*/
350355
@Override
351-
public boolean equals(Object o) {
356+
public boolean equals(@Nullable Object o) {
352357

353358
if (this == o) {
354359
return true;
@@ -363,6 +368,7 @@ public boolean equals(Object o) {
363368
}
364369

365370
ParentParameterTypes that = (ParentParameterTypes) o;
371+
366372
return ObjectUtils.nullSafeEquals(tail, that.tail);
367373
}
368374

@@ -372,8 +378,11 @@ public boolean equals(Object o) {
372378
*/
373379
@Override
374380
public int hashCode() {
381+
375382
int result = super.hashCode();
383+
376384
result = 31 * result + ObjectUtils.nullSafeHashCode(tail);
385+
377386
return result;
378387
}
379388
}

src/main/java/org/springframework/data/util/TypeDiscoverer.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,7 @@
2424
import java.lang.reflect.Type;
2525
import java.lang.reflect.TypeVariable;
2626
import java.lang.reflect.WildcardType;
27-
import java.util.ArrayList;
28-
import java.util.Arrays;
29-
import java.util.Collection;
30-
import java.util.Collections;
31-
import java.util.HashMap;
32-
import java.util.HashSet;
33-
import java.util.List;
34-
import java.util.Map;
35-
import java.util.Optional;
36-
import java.util.Set;
27+
import java.util.*;
3728
import java.util.concurrent.ConcurrentHashMap;
3829
import java.util.stream.Collectors;
3930

@@ -629,7 +620,7 @@ public Type[] getActualTypeArguments() {
629620
* @see org.springframework.data.util.ParentTypeAwareTypeInformation#equals(java.lang.Object)
630621
*/
631622
@Override
632-
public boolean equals(Object o) {
623+
public boolean equals(@Nullable Object o) {
633624

634625
if (this == o) {
635626
return true;

src/main/java/org/springframework/data/web/HateoasSortHandlerMethodArgumentResolver.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
* @author Thomas Darimont
3838
* @author Nick Williams
3939
*/
40-
@SuppressWarnings("null")
4140
public class HateoasSortHandlerMethodArgumentResolver extends SortHandlerMethodArgumentResolver
4241
implements UriComponentsContributor {
4342

src/main/java/org/springframework/data/web/JsonProjectingMethodInterceptorFactory.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929

3030
import org.aopalliance.intercept.MethodInterceptor;
3131
import org.aopalliance.intercept.MethodInvocation;
32-
3332
import org.springframework.core.ResolvableType;
3433
import org.springframework.core.annotation.AnnotationUtils;
3534
import org.springframework.data.projection.Accessor;
@@ -136,7 +135,7 @@ public InputMessageProjecting(DocumentContext context) {
136135
*/
137136
@Nullable
138137
@Override
139-
public Object invoke(@SuppressWarnings("null") MethodInvocation invocation) throws Throwable {
138+
public Object invoke(MethodInvocation invocation) throws Throwable {
140139

141140
Method method = invocation.getMethod();
142141
TypeInformation<Object> returnType = ClassTypeInformation.fromReturnTypeOf(method);

src/main/java/org/springframework/data/web/PagedResourcesAssembler.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ public void setForceFirstAndLastRels(boolean forceFirstAndLastRels) {
9292
* @see org.springframework.hateoas.server.RepresentationModelAssembler#toModel(java.lang.Object)
9393
*/
9494
@Override
95-
@SuppressWarnings("null")
9695
public PagedModel<EntityModel<T>> toModel(Page<T> entity) {
9796
return toModel(entity, EntityModel::of);
9897
}

src/main/java/org/springframework/data/web/PagedResourcesAssemblerArgumentResolver.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
*/
5050
public class PagedResourcesAssemblerArgumentResolver implements HandlerMethodArgumentResolver {
5151

52-
private static final Log logger = LogFactory.getLog(PagedResourcesAssemblerArgumentResolver.class);
52+
private static final Log logger = LogFactory.getLog(PagedResourcesAssemblerArgumentResolver.class);
5353

5454
private static final String SUPERFLOUS_QUALIFIER = "Found qualified %s parameter, but a unique unqualified %s parameter. Using that one, but you might want to check your controller method configuration!";
5555
private static final String PARAMETER_AMBIGUITY = "Discovered multiple parameters of type Pageable but no qualifier annotations to disambiguate!";
@@ -152,7 +152,8 @@ private static MethodParameter findMatchingPageableParameter(MethodParameter par
152152
MethodParameter matchingParameter = returnIfQualifiersMatch(pageableParameter, assemblerQualifier);
153153

154154
if (matchingParameter == null) {
155-
logger.info(LogMessage.format(SUPERFLOUS_QUALIFIER, PagedResourcesAssembler.class.getSimpleName(), Pageable.class.getName()));
155+
logger.info(LogMessage.format(SUPERFLOUS_QUALIFIER, PagedResourcesAssembler.class.getSimpleName(),
156+
Pageable.class.getName()));
156157
}
157158

158159
return pageableParameter;

0 commit comments

Comments
 (0)