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.
This commit is contained in:
Oliver Drotbohm
2020-09-22 22:22:20 +02:00
parent 5876bd2e5a
commit af9dd6110d
10 changed files with 60 additions and 33 deletions

View File

@@ -155,7 +155,10 @@ public final class KotlinReflectionUtils {
}
private static boolean isLast(MethodParameter parameter) {
return parameter.getParameterIndex() == parameter.getMethod().getParameterCount() - 1;
Method method = parameter.getMethod();
return method != null && parameter.getParameterIndex() == method.getParameterCount() - 1;
}
/**

View File

@@ -38,14 +38,29 @@ public class Lazy<T> implements Supplier<T> {
private final Supplier<? extends T> supplier;
private @Nullable T value = null;
private boolean resolved = false;
private @Nullable T value;
private boolean resolved;
/**
* Creates a new {@link Lazy} instance for the given supplier.
*
* @param supplier
* @deprecated prefer {@link Lazy#of(Supplier)}, to be turned private in 2.5.
*/
@Deprecated
public Lazy(Supplier<? extends T> supplier) {
this.supplier = supplier;
this(supplier, null, false);
}
private Lazy(Supplier<? extends T> supplier, T value, boolean resolved) {
/**
* Creates a new {@link Lazy} for the given {@link Supplier}, value and whether it has been resolved or not.
*
* @param supplier must not be {@literal null}.
* @param value can be {@literal null}.
* @param resolved whether the value handed into the constructor represents a resolved value.
*/
private Lazy(Supplier<? extends T> supplier, @Nullable T value, boolean resolved) {
this.supplier = supplier;
this.value = value;
this.resolved = resolved;
@@ -226,7 +241,7 @@ public class Lazy<T> implements Supplier<T> {
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object o) {
public boolean equals(@Nullable Object o) {
if (this == o) {
return true;
@@ -255,9 +270,12 @@ public class Lazy<T> implements Supplier<T> {
*/
@Override
public int hashCode() {
int result = ObjectUtils.nullSafeHashCode(supplier);
result = 31 * result + ObjectUtils.nullSafeHashCode(value);
result = 31 * result + (resolved ? 1 : 0);
return result;
}
}

View File

@@ -25,10 +25,10 @@ import java.util.Optional;
import java.util.function.Function;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.core.CollectionFactory;
import org.springframework.core.ResolvableType;
import org.springframework.lang.NonNull;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
@@ -170,9 +170,12 @@ public class MethodInvocationRecorder {
private static final InvocationInformation NOT_INVOKED = new InvocationInformation(new Unrecorded(), null);
private final Recorded<?> recorded;
@Nullable private final Method invokedMethod;
private final @Nullable Method invokedMethod;
public InvocationInformation(Recorded<?> recorded, @Nullable Method invokedMethod) {
Assert.notNull(recorded, "Recorded must not be null!");
public InvocationInformation(Recorded<?> recorded, Method invokedMethod) {
this.recorded = recorded;
this.invokedMethod = invokedMethod;
}
@@ -220,7 +223,7 @@ public class MethodInvocationRecorder {
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object o) {
public boolean equals(@Nullable Object o) {
if (this == o) {
return true;
@@ -245,8 +248,11 @@ public class MethodInvocationRecorder {
*/
@Override
public int hashCode() {
int result = ObjectUtils.nullSafeHashCode(recorded);
result = 31 * result + ObjectUtils.nullSafeHashCode(invokedMethod);
return result;
}
@@ -275,7 +281,7 @@ public class MethodInvocationRecorder {
* (non-Javadoc)
* @see org.springframework.hateoas.core.Recorder.PropertyNameDetectionStrategy#getPropertyName(java.lang.reflect.Method)
*/
@NonNull
@Override
public String getPropertyName(Method method) {
return getPropertyName(method.getReturnType(), method.getName());
@@ -299,7 +305,8 @@ public class MethodInvocationRecorder {
private final @Nullable T currentInstance;
private final @Nullable MethodInvocationRecorder recorder;
public Recorded(T currentInstance, MethodInvocationRecorder recorder) {
Recorded(@Nullable T currentInstance, @Nullable MethodInvocationRecorder recorder) {
this.currentInstance = currentInstance;
this.recorder = recorder;
}
@@ -367,6 +374,7 @@ public class MethodInvocationRecorder {
*/
@Override
public String toString() {
return "MethodInvocationRecorder.Recorded(currentInstance=" + this.currentInstance + ", recorder=" + this.recorder
+ ")";
}
@@ -378,7 +386,6 @@ public class MethodInvocationRecorder {
static class Unrecorded extends Recorded<Object> {
@SuppressWarnings("null")
private Unrecorded() {
super(null, null);
}

View File

@@ -20,6 +20,7 @@ import java.util.stream.Collector;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
@@ -90,7 +91,7 @@ public final class Pair<S, T> {
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object o) {
public boolean equals(@Nullable Object o) {
if (this == o) {
return true;

View File

@@ -26,6 +26,7 @@ import java.util.concurrent.ConcurrentMap;
import java.util.stream.Collectors;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ConcurrentReferenceHashMap;
import org.springframework.util.ObjectUtils;
@@ -282,14 +283,18 @@ public class ParameterTypes {
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object o) {
public boolean equals(@Nullable Object o) {
if (this == o) {
return true;
}
if (!(o instanceof ParameterTypes)) {
return false;
}
ParameterTypes that = (ParameterTypes) o;
return ObjectUtils.nullSafeEquals(types, that.types);
}
@@ -348,7 +353,7 @@ public class ParameterTypes {
* @see org.springframework.data.util.ParentTypeAwareTypeInformation#equals(java.lang.Object)
*/
@Override
public boolean equals(Object o) {
public boolean equals(@Nullable Object o) {
if (this == o) {
return true;
@@ -363,6 +368,7 @@ public class ParameterTypes {
}
ParentParameterTypes that = (ParentParameterTypes) o;
return ObjectUtils.nullSafeEquals(tail, that.tail);
}
@@ -372,8 +378,11 @@ public class ParameterTypes {
*/
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + ObjectUtils.nullSafeHashCode(tail);
return result;
}
}

View File

@@ -24,16 +24,7 @@ import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import java.lang.reflect.WildcardType;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
@@ -629,7 +620,7 @@ class TypeDiscoverer<S> implements TypeInformation<S> {
* @see org.springframework.data.util.ParentTypeAwareTypeInformation#equals(java.lang.Object)
*/
@Override
public boolean equals(Object o) {
public boolean equals(@Nullable Object o) {
if (this == o) {
return true;

View File

@@ -37,7 +37,6 @@ import org.springframework.web.util.UriComponentsBuilder;
* @author Thomas Darimont
* @author Nick Williams
*/
@SuppressWarnings("null")
public class HateoasSortHandlerMethodArgumentResolver extends SortHandlerMethodArgumentResolver
implements UriComponentsContributor {

View File

@@ -29,7 +29,6 @@ import java.util.Map;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.core.ResolvableType;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.data.projection.Accessor;
@@ -136,7 +135,7 @@ public class JsonProjectingMethodInterceptorFactory implements MethodInterceptor
*/
@Nullable
@Override
public Object invoke(@SuppressWarnings("null") MethodInvocation invocation) throws Throwable {
public Object invoke(MethodInvocation invocation) throws Throwable {
Method method = invocation.getMethod();
TypeInformation<Object> returnType = ClassTypeInformation.fromReturnTypeOf(method);

View File

@@ -92,7 +92,6 @@ public class PagedResourcesAssembler<T> implements RepresentationModelAssembler<
* @see org.springframework.hateoas.server.RepresentationModelAssembler#toModel(java.lang.Object)
*/
@Override
@SuppressWarnings("null")
public PagedModel<EntityModel<T>> toModel(Page<T> entity) {
return toModel(entity, EntityModel::of);
}

View File

@@ -49,7 +49,7 @@ import org.springframework.web.util.UriComponentsBuilder;
*/
public class PagedResourcesAssemblerArgumentResolver implements HandlerMethodArgumentResolver {
private static final Log logger = LogFactory.getLog(PagedResourcesAssemblerArgumentResolver.class);
private static final Log logger = LogFactory.getLog(PagedResourcesAssemblerArgumentResolver.class);
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!";
private static final String PARAMETER_AMBIGUITY = "Discovered multiple parameters of type Pageable but no qualifier annotations to disambiguate!";
@@ -152,7 +152,8 @@ public class PagedResourcesAssemblerArgumentResolver implements HandlerMethodArg
MethodParameter matchingParameter = returnIfQualifiersMatch(pageableParameter, assemblerQualifier);
if (matchingParameter == null) {
logger.info(LogMessage.format(SUPERFLOUS_QUALIFIER, PagedResourcesAssembler.class.getSimpleName(), Pageable.class.getName()));
logger.info(LogMessage.format(SUPERFLOUS_QUALIFIER, PagedResourcesAssembler.class.getSimpleName(),
Pageable.class.getName()));
}
return pageableParameter;