Add more @Nullable parameters based on null usage
Issue: SPR-15540
This commit is contained in:
@@ -74,7 +74,7 @@ public class OrderComparator implements Comparator<Object> {
|
||||
return doCompare(o1, o2, null);
|
||||
}
|
||||
|
||||
private int doCompare(Object o1, Object o2, OrderSourceProvider sourceProvider) {
|
||||
private int doCompare(Object o1, Object o2, @Nullable OrderSourceProvider sourceProvider) {
|
||||
boolean p1 = (o1 instanceof PriorityOrdered);
|
||||
boolean p2 = (o2 instanceof PriorityOrdered);
|
||||
if (p1 && !p2) {
|
||||
|
||||
@@ -122,7 +122,7 @@ public class ReactiveAdapterRegistry {
|
||||
* (i.e. to adapt from; may be {@code null} if the reactive type is specified)
|
||||
*/
|
||||
@Nullable
|
||||
public ReactiveAdapter getAdapter(@Nullable Class<?> reactiveType, Object source) {
|
||||
public ReactiveAdapter getAdapter(@Nullable Class<?> reactiveType, @Nullable Object source) {
|
||||
|
||||
Object sourceToUse = (source instanceof Optional ? ((Optional<?>) source).orElse(null) : source);
|
||||
Class<?> clazz = (sourceToUse != null ? sourceToUse.getClass() : reactiveType);
|
||||
|
||||
@@ -17,6 +17,7 @@ package org.springframework.core;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -42,7 +43,7 @@ public class ReactiveTypeDescriptor {
|
||||
/**
|
||||
* Private constructor. See static factory methods.
|
||||
*/
|
||||
private ReactiveTypeDescriptor(Class<?> reactiveType, Supplier<?> emptySupplier,
|
||||
private ReactiveTypeDescriptor(Class<?> reactiveType, @Nullable Supplier<?> emptySupplier,
|
||||
boolean multiValue, boolean canBeEmpty, boolean noValue) {
|
||||
|
||||
Assert.notNull(reactiveType, "'reactiveType' must not be null");
|
||||
|
||||
@@ -146,7 +146,7 @@ public class ResolvableType implements Serializable {
|
||||
* with upfront resolution and a pre-calculated hash.
|
||||
* @since 4.2
|
||||
*/
|
||||
private ResolvableType(Type type, TypeProvider typeProvider, VariableResolver variableResolver, Integer hash) {
|
||||
private ResolvableType(@Nullable Type type, @Nullable TypeProvider typeProvider, @Nullable VariableResolver variableResolver, Integer hash) {
|
||||
this.type = type;
|
||||
this.typeProvider = typeProvider;
|
||||
this.variableResolver = variableResolver;
|
||||
@@ -160,7 +160,7 @@ public class ResolvableType implements Serializable {
|
||||
* with upfront resolution but lazily calculated hash.
|
||||
*/
|
||||
private ResolvableType(
|
||||
Type type, TypeProvider typeProvider, VariableResolver variableResolver, ResolvableType componentType) {
|
||||
Type type, @Nullable TypeProvider typeProvider, @Nullable VariableResolver variableResolver, ResolvableType componentType) {
|
||||
|
||||
this.type = type;
|
||||
this.typeProvider = typeProvider;
|
||||
@@ -257,7 +257,7 @@ public class ResolvableType implements Serializable {
|
||||
return isAssignableFrom(other, null);
|
||||
}
|
||||
|
||||
private boolean isAssignableFrom(ResolvableType other, Map<Type, Type> matchedBefore) {
|
||||
private boolean isAssignableFrom(ResolvableType other, @Nullable Map<Type, Type> matchedBefore) {
|
||||
Assert.notNull(other, "ResolvableType must not be null");
|
||||
|
||||
// If we cannot resolve types, we are not assignable
|
||||
@@ -700,7 +700,7 @@ public class ResolvableType implements Serializable {
|
||||
* @see #getGenerics()
|
||||
* @see #resolve()
|
||||
*/
|
||||
public Class<?>[] resolveGenerics(Class<?> fallback) {
|
||||
public Class<?>[] resolveGenerics(@Nullable Class<?> fallback) {
|
||||
ResolvableType[] generics = getGenerics();
|
||||
Class<?>[] resolvedGenerics = new Class<?>[generics.length];
|
||||
for (int i = 0; i < generics.length; i++) {
|
||||
|
||||
@@ -241,8 +241,8 @@ public class AnnotatedElementUtils {
|
||||
return hasMetaAnnotationTypes(element, null, annotationName);
|
||||
}
|
||||
|
||||
private static boolean hasMetaAnnotationTypes(AnnotatedElement element, Class<? extends Annotation> annotationType,
|
||||
String annotationName) {
|
||||
private static boolean hasMetaAnnotationTypes(AnnotatedElement element, @Nullable Class<? extends Annotation> annotationType,
|
||||
@Nullable String annotationName) {
|
||||
|
||||
return Boolean.TRUE.equals(
|
||||
searchWithGetSemantics(element, annotationType, annotationName, new SimpleAnnotationProcessor<Boolean>() {
|
||||
@@ -844,8 +844,8 @@ public class AnnotatedElementUtils {
|
||||
* @return the result of the processor, potentially {@code null}
|
||||
*/
|
||||
@Nullable
|
||||
private static <T> T searchWithGetSemantics(AnnotatedElement element, Class<? extends Annotation> annotationType,
|
||||
String annotationName, Processor<T> processor) {
|
||||
private static <T> T searchWithGetSemantics(AnnotatedElement element, @Nullable Class<? extends Annotation> annotationType,
|
||||
@Nullable String annotationName, Processor<T> processor) {
|
||||
|
||||
return searchWithGetSemantics(element, annotationType, annotationName, null, processor);
|
||||
}
|
||||
@@ -866,7 +866,7 @@ public class AnnotatedElementUtils {
|
||||
*/
|
||||
@Nullable
|
||||
private static <T> T searchWithGetSemantics(AnnotatedElement element, Class<? extends Annotation> annotationType,
|
||||
String annotationName, @Nullable Class<? extends Annotation> containerType, Processor<T> processor) {
|
||||
@Nullable String annotationName, @Nullable Class<? extends Annotation> containerType, Processor<T> processor) {
|
||||
|
||||
try {
|
||||
return searchWithGetSemantics(element, annotationType, annotationName, containerType, processor,
|
||||
@@ -896,8 +896,8 @@ public class AnnotatedElementUtils {
|
||||
* @return the result of the processor, potentially {@code null}
|
||||
*/
|
||||
@Nullable
|
||||
private static <T> T searchWithGetSemantics(AnnotatedElement element, Class<? extends Annotation> annotationType,
|
||||
String annotationName, @Nullable Class<? extends Annotation> containerType, Processor<T> processor,
|
||||
private static <T> T searchWithGetSemantics(AnnotatedElement element, @Nullable Class<? extends Annotation> annotationType,
|
||||
@Nullable String annotationName, @Nullable Class<? extends Annotation> containerType, Processor<T> processor,
|
||||
Set<AnnotatedElement> visited, int metaDepth) {
|
||||
|
||||
Assert.notNull(element, "AnnotatedElement must not be null");
|
||||
@@ -1029,8 +1029,8 @@ public class AnnotatedElementUtils {
|
||||
* @since 4.2
|
||||
*/
|
||||
@Nullable
|
||||
private static <T> T searchWithFindSemantics(AnnotatedElement element, Class<? extends Annotation> annotationType,
|
||||
String annotationName, Processor<T> processor) {
|
||||
private static <T> T searchWithFindSemantics(AnnotatedElement element, @Nullable Class<? extends Annotation> annotationType,
|
||||
@Nullable String annotationName, Processor<T> processor) {
|
||||
|
||||
return searchWithFindSemantics(element, annotationType, annotationName, null, processor);
|
||||
}
|
||||
@@ -1051,7 +1051,7 @@ public class AnnotatedElementUtils {
|
||||
*/
|
||||
@Nullable
|
||||
private static <T> T searchWithFindSemantics(AnnotatedElement element, Class<? extends Annotation> annotationType,
|
||||
String annotationName, @Nullable Class<? extends Annotation> containerType, Processor<T> processor) {
|
||||
@Nullable String annotationName, @Nullable Class<? extends Annotation> containerType, Processor<T> processor) {
|
||||
|
||||
if (containerType != null && !processor.aggregates()) {
|
||||
throw new IllegalArgumentException(
|
||||
|
||||
@@ -48,7 +48,7 @@ public class ByteArrayDecoder extends AbstractDecoder<byte[]> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Flux<byte[]> decode(Publisher<DataBuffer> inputStream, ResolvableType elementType,
|
||||
public Flux<byte[]> decode(Publisher<DataBuffer> inputStream,@Nullable ResolvableType elementType,
|
||||
@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
|
||||
|
||||
return Flux.from(inputStream).map((dataBuffer) -> {
|
||||
|
||||
@@ -50,7 +50,7 @@ public class ByteBufferDecoder extends AbstractDecoder<ByteBuffer> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Flux<ByteBuffer> decode(Publisher<DataBuffer> inputStream, ResolvableType elementType,
|
||||
public Flux<ByteBuffer> decode(Publisher<DataBuffer> inputStream, @Nullable ResolvableType elementType,
|
||||
@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
|
||||
|
||||
return Flux.from(inputStream).map((dataBuffer) -> {
|
||||
|
||||
@@ -50,7 +50,7 @@ public class DataBufferDecoder extends AbstractDecoder<DataBuffer> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Flux<DataBuffer> decode(Publisher<DataBuffer> inputStream, ResolvableType elementType,
|
||||
public Flux<DataBuffer> decode(Publisher<DataBuffer> inputStream, @Nullable ResolvableType elementType,
|
||||
@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
|
||||
return Flux.from(inputStream);
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ public interface Decoder<T> {
|
||||
* @param hints additional information about how to do encode
|
||||
* @return the output stream with decoded elements
|
||||
*/
|
||||
Flux<T> decode(Publisher<DataBuffer> inputStream, ResolvableType elementType,
|
||||
Flux<T> decode(Publisher<DataBuffer> inputStream, @Nullable ResolvableType elementType,
|
||||
@Nullable MimeType mimeType, @Nullable Map<String, Object> hints);
|
||||
|
||||
/**
|
||||
|
||||
@@ -55,7 +55,7 @@ public class ResourceDecoder extends AbstractDecoder<Resource> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Flux<Resource> decode(Publisher<DataBuffer> inputStream, ResolvableType elementType,
|
||||
public Flux<Resource> decode(Publisher<DataBuffer> inputStream, @Nullable ResolvableType elementType,
|
||||
@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
|
||||
|
||||
return Flux.from(decodeToMono(inputStream, elementType, mimeType, hints));
|
||||
|
||||
@@ -77,7 +77,7 @@ public class StringDecoder extends AbstractDecoder<String> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Flux<String> decode(Publisher<DataBuffer> inputStream, ResolvableType elementType,
|
||||
public Flux<String> decode(Publisher<DataBuffer> inputStream, @Nullable ResolvableType elementType,
|
||||
@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
|
||||
|
||||
Flux<DataBuffer> inputFlux = Flux.from(inputStream);
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.core.convert;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
@@ -42,7 +43,7 @@ public class ConversionFailedException extends ConversionException {
|
||||
* @param value the value we tried to convert
|
||||
* @param cause the cause of the conversion failure
|
||||
*/
|
||||
public ConversionFailedException(TypeDescriptor sourceType, TypeDescriptor targetType, Object value, Throwable cause) {
|
||||
public ConversionFailedException(TypeDescriptor sourceType, TypeDescriptor targetType, @Nullable Object value, Throwable cause) {
|
||||
super("Failed to convert from type [" + sourceType + "] to type [" + targetType +
|
||||
"] for value '" + ObjectUtils.nullSafeToString(value) + "'", cause);
|
||||
this.sourceType = sourceType;
|
||||
|
||||
@@ -63,7 +63,7 @@ public final class Property {
|
||||
private Annotation[] annotations;
|
||||
|
||||
|
||||
public Property(Class<?> objectType, Method readMethod, Method writeMethod) {
|
||||
public Property(Class<?> objectType, @Nullable Method readMethod, @Nullable Method writeMethod) {
|
||||
this(objectType, readMethod, writeMethod, null);
|
||||
}
|
||||
|
||||
|
||||
@@ -118,7 +118,7 @@ public class TypeDescriptor implements Serializable {
|
||||
* @param annotations the type annotations
|
||||
* @since 4.0
|
||||
*/
|
||||
protected TypeDescriptor(ResolvableType resolvableType, @Nullable Class<?> type, Annotation[] annotations) {
|
||||
protected TypeDescriptor(ResolvableType resolvableType, @Nullable Class<?> type, @Nullable Annotation[] annotations) {
|
||||
this.resolvableType = resolvableType;
|
||||
this.type = (type != null ? type : resolvableType.resolve(Object.class));
|
||||
this.annotatedElement = new AnnotatedElementAdapter(annotations);
|
||||
|
||||
@@ -230,7 +230,7 @@ public class GenericConversionService implements ConfigurableConversionService {
|
||||
* @return the converted null object
|
||||
*/
|
||||
@Nullable
|
||||
protected Object convertNullSource(TypeDescriptor sourceType, TypeDescriptor targetType) {
|
||||
protected Object convertNullSource(@Nullable TypeDescriptor sourceType, TypeDescriptor targetType) {
|
||||
if (targetType.getObjectType() == Optional.class) {
|
||||
return Optional.empty();
|
||||
}
|
||||
@@ -317,7 +317,7 @@ public class GenericConversionService implements ConfigurableConversionService {
|
||||
throw new ConverterNotFoundException(sourceType, targetType);
|
||||
}
|
||||
|
||||
private Object handleResult(TypeDescriptor sourceType, TypeDescriptor targetType, Object result) {
|
||||
private Object handleResult(@Nullable TypeDescriptor sourceType, TypeDescriptor targetType, Object result) {
|
||||
if (result == null) {
|
||||
assertNotPrimitiveTargetType(sourceType, targetType);
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import java.lang.reflect.Method;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
/**
|
||||
@@ -95,7 +96,7 @@ public abstract class VfsUtils {
|
||||
}
|
||||
}
|
||||
|
||||
protected static Object invokeVfsMethod(Method method, Object target, Object... args) throws IOException {
|
||||
protected static Object invokeVfsMethod(Method method, @Nullable Object target, Object... args) throws IOException {
|
||||
try {
|
||||
return method.invoke(target, args);
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import java.util.Properties;
|
||||
import org.springframework.core.env.PropertiesPropertySource;
|
||||
import org.springframework.core.io.DefaultResourceLoader;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
@@ -124,7 +125,7 @@ public class ResourcePropertySource extends PropertiesPropertySource {
|
||||
this(new DefaultResourceLoader().getResource(location));
|
||||
}
|
||||
|
||||
private ResourcePropertySource(String name, String resourceName, Map<String, Object> source) {
|
||||
private ResourcePropertySource(String name, @Nullable String resourceName, Map<String, Object> source) {
|
||||
super(name, source);
|
||||
this.resourceName = resourceName;
|
||||
}
|
||||
|
||||
@@ -25,6 +25,8 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* {@link PathMatcher} implementation for Ant-style path patterns.
|
||||
*
|
||||
@@ -187,7 +189,7 @@ public class AntPathMatcher implements PathMatcher {
|
||||
* as far as the given base path goes is sufficient)
|
||||
* @return {@code true} if the supplied {@code path} matched, {@code false} if it didn't
|
||||
*/
|
||||
protected boolean doMatch(String pattern, String path, boolean fullMatch, Map<String, String> uriTemplateVariables) {
|
||||
protected boolean doMatch(String pattern, String path, boolean fullMatch, @Nullable Map<String, String> uriTemplateVariables) {
|
||||
if (path.startsWith(this.pathSeparator) != pattern.startsWith(this.pathSeparator)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -411,7 +411,7 @@ public abstract class CollectionUtils {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(K key, V value) {
|
||||
public void add(K key, @Nullable V value) {
|
||||
List<V> values = this.map.computeIfAbsent(key, k -> new LinkedList<>());
|
||||
values.add(value);
|
||||
}
|
||||
|
||||
@@ -24,6 +24,8 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Simple implementation of {@link MultiValueMap} that wraps a {@link LinkedHashMap},
|
||||
* storing multiple values in a {@link LinkedList}.
|
||||
@@ -74,7 +76,7 @@ public class LinkedMultiValueMap<K, V> implements MultiValueMap<K, V>, Serializa
|
||||
// MultiValueMap implementation
|
||||
|
||||
@Override
|
||||
public void add(K key, V value) {
|
||||
public void add(K key, @Nullable V value) {
|
||||
List<V> values = this.targetMap.computeIfAbsent(key, k -> new LinkedList<>());
|
||||
values.add(value);
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ public interface MultiValueMap<K, V> extends Map<K, List<V>> {
|
||||
* @param key the key
|
||||
* @param value the value to be added
|
||||
*/
|
||||
void add(K key, V value);
|
||||
void add(K key, @Nullable V value);
|
||||
|
||||
/**
|
||||
* Add all the values of the given list to the current list of values for the given key.
|
||||
|
||||
@@ -238,7 +238,7 @@ public abstract class ReflectionUtils {
|
||||
* @see #invokeJdbcMethod(java.lang.reflect.Method, Object, Object[])
|
||||
*/
|
||||
@Nullable
|
||||
public static Object invokeJdbcMethod(Method method, Object target) throws SQLException {
|
||||
public static Object invokeJdbcMethod(Method method, @Nullable Object target) throws SQLException {
|
||||
return invokeJdbcMethod(method, target, new Object[0]);
|
||||
}
|
||||
|
||||
@@ -547,7 +547,7 @@ public abstract class ReflectionUtils {
|
||||
* @param mf the filter that determines the methods to apply the callback to
|
||||
* @throws IllegalStateException if introspection fails
|
||||
*/
|
||||
public static void doWithMethods(Class<?> clazz, MethodCallback mc, MethodFilter mf) {
|
||||
public static void doWithMethods(Class<?> clazz, MethodCallback mc, @Nullable MethodFilter mf) {
|
||||
// Keep backing up the inheritance hierarchy.
|
||||
Method[] methods = getDeclaredMethods(clazz);
|
||||
for (Method method : methods) {
|
||||
@@ -720,7 +720,7 @@ public abstract class ReflectionUtils {
|
||||
* @param ff the filter that determines the fields to apply the callback to
|
||||
* @throws IllegalStateException if introspection fails
|
||||
*/
|
||||
public static void doWithFields(Class<?> clazz, FieldCallback fc, FieldFilter ff) {
|
||||
public static void doWithFields(Class<?> clazz, FieldCallback fc, @Nullable FieldFilter ff) {
|
||||
// Keep backing up the inheritance hierarchy.
|
||||
Class<?> targetClass = clazz;
|
||||
do {
|
||||
|
||||
@@ -1065,7 +1065,7 @@ public abstract class StringUtils {
|
||||
*/
|
||||
@Nullable
|
||||
public static Properties splitArrayElementsIntoProperties(
|
||||
String[] array, String delimiter, String charsToDelete) {
|
||||
String[] array, String delimiter, @Nullable String charsToDelete) {
|
||||
|
||||
if (ObjectUtils.isEmpty(array)) {
|
||||
return null;
|
||||
@@ -1179,7 +1179,7 @@ public abstract class StringUtils {
|
||||
* @return an array of the tokens in the list
|
||||
* @see #tokenizeToStringArray
|
||||
*/
|
||||
public static String[] delimitedListToStringArray(String str, String delimiter, String charsToDelete) {
|
||||
public static String[] delimitedListToStringArray(String str, String delimiter, @Nullable String charsToDelete) {
|
||||
if (str == null) {
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
@@ -20,6 +20,8 @@ import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.FutureTask;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Extension of {@link FutureTask} that implements {@link ListenableFuture}.
|
||||
*
|
||||
@@ -47,7 +49,7 @@ public class ListenableFutureTask<T> extends FutureTask<T> implements Listenable
|
||||
* @param runnable the runnable task
|
||||
* @param result the result to return on successful completion
|
||||
*/
|
||||
public ListenableFutureTask(Runnable runnable, T result) {
|
||||
public ListenableFutureTask(Runnable runnable, @Nullable T result) {
|
||||
super(runnable, result);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -54,7 +55,7 @@ public class SettableListenableFuture<T> implements ListenableFuture<T> {
|
||||
* @param value the value that will be set
|
||||
* @return {@code true} if the value was successfully set, else {@code false}
|
||||
*/
|
||||
public boolean set(T value) {
|
||||
public boolean set(@Nullable T value) {
|
||||
return this.settableTask.setResultValue(value);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user