Backport selected refinements from the nullability efforts

Issue: SPR-15656
This commit is contained in:
Juergen Hoeller
2017-09-27 00:09:58 +02:00
parent 18a3322d2f
commit 9fdc4404a5
194 changed files with 1236 additions and 1218 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -75,7 +75,7 @@ public final class MethodClassKey implements Comparable<MethodClassKey> {
int result = this.method.getName().compareTo(other.method.getName());
if (result == 0) {
result = this.method.toString().compareTo(other.method.toString());
if (result == 0 && this.targetClass != null) {
if (result == 0 && this.targetClass != null && other.targetClass != null) {
result = this.targetClass.getName().compareTo(other.targetClass.getName());
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,7 +24,7 @@ package org.springframework.core;
*
* <p>Users of this interface should be careful in complex hierarchy scenarios, especially
* when the generic type signature of the class changes in sub-classes. It is always
* possible to return {@code null} to fallback on a default behaviour.
* possible to return {@code null} to fallback on a default behavior.
*
* @author Stephane Nicoll
* @since 4.2

View File

@@ -35,19 +35,19 @@ import org.springframework.util.ConcurrentReferenceHashMap;
import org.springframework.util.ReflectionUtils;
/**
* Internal utility class that can be used to obtain wrapped {@link Serializable} variants
* of {@link java.lang.reflect.Type}s.
* Internal utility class that can be used to obtain wrapped {@link Serializable}
* variants of {@link java.lang.reflect.Type}s.
*
* <p>{@link #forField(Field) Fields} or {@link #forMethodParameter(MethodParameter)
* MethodParameters} can be used as the root source for a serializable type. Alternatively
* the {@link #forGenericSuperclass(Class) superclass},
* MethodParameters} can be used as the root source for a serializable type.
* Alternatively the {@link #forGenericSuperclass(Class) superclass},
* {@link #forGenericInterfaces(Class) interfaces} or {@link #forTypeParameters(Class)
* type parameters} or a regular {@link Class} can also be used as source.
*
* <p>The returned type will either be a {@link Class} or a serializable proxy of
* {@link GenericArrayType}, {@link ParameterizedType}, {@link TypeVariable} or
* {@link WildcardType}. With the exception of {@link Class} (which is final) calls to
* methods that return further {@link Type}s (for example
* {@link WildcardType}. With the exception of {@link Class} (which is final) calls
* to methods that return further {@link Type}s (for example
* {@link GenericArrayType#getGenericComponentType()}) will be automatically wrapped.
*
* @author Phillip Webb

View File

@@ -1441,8 +1441,8 @@ public class AnnotatedElementUtils {
* <p>If this method returns {@code true}, then {@link #getAggregatedResults()}
* must return a non-null value.
* @return {@code true} if this processor supports aggregated results
* @see #getAggregatedResults
* @since 4.3
* @see #getAggregatedResults
*/
boolean aggregates();
@@ -1453,10 +1453,9 @@ public class AnnotatedElementUtils {
* responsible for asking this processor if it {@link #aggregates} results
* and then adding the post-processed results to the list returned by this
* method.
* @return the list of results aggregated by this processor
* (never {@code null} unless {@link #aggregates} returns {@code false})
* @see #aggregates
* @return the list of results aggregated by this processor (never {@code null})
* @since 4.3
* @see #aggregates
*/
List<T> getAggregatedResults();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -243,10 +243,9 @@ public class AnnotationAttributes extends LinkedHashMap<String, Object> {
}
/**
* Get the value stored under the specified {@code attributeName} as a
* boolean.
* @param attributeName the name of the attribute to get; never
* {@code null} or empty
* Get the value stored under the specified {@code attributeName} as a boolean.
* @param attributeName the name of the attribute to get;
* never {@code null} or empty
* @return the value
* @throws IllegalArgumentException if the attribute does not exist or
* if it is not of the expected type
@@ -256,10 +255,9 @@ public class AnnotationAttributes extends LinkedHashMap<String, Object> {
}
/**
* Get the value stored under the specified {@code attributeName} as a
* number.
* @param attributeName the name of the attribute to get; never
* {@code null} or empty
* Get the value stored under the specified {@code attributeName} as a number.
* @param attributeName the name of the attribute to get;
* never {@code null} or empty
* @return the value
* @throws IllegalArgumentException if the attribute does not exist or
* if it is not of the expected type
@@ -270,10 +268,9 @@ public class AnnotationAttributes extends LinkedHashMap<String, Object> {
}
/**
* Get the value stored under the specified {@code attributeName} as an
* enum.
* @param attributeName the name of the attribute to get; never
* {@code null} or empty
* Get the value stored under the specified {@code attributeName} as an enum.
* @param attributeName the name of the attribute to get;
* never {@code null} or empty
* @return the value
* @throws IllegalArgumentException if the attribute does not exist or
* if it is not of the expected type
@@ -284,10 +281,9 @@ public class AnnotationAttributes extends LinkedHashMap<String, Object> {
}
/**
* Get the value stored under the specified {@code attributeName} as a
* class.
* @param attributeName the name of the attribute to get; never
* {@code null} or empty
* Get the value stored under the specified {@code attributeName} as a class.
* @param attributeName the name of the attribute to get;
* never {@code null} or empty
* @return the value
* @throws IllegalArgumentException if the attribute does not exist or
* if it is not of the expected type
@@ -300,11 +296,10 @@ public class AnnotationAttributes extends LinkedHashMap<String, Object> {
/**
* Get the value stored under the specified {@code attributeName} as an
* array of classes.
* <p>If the value stored under the specified {@code attributeName} is
* a class, it will be wrapped in a single-element array before
* returning it.
* @param attributeName the name of the attribute to get; never
* {@code null} or empty
* <p>If the value stored under the specified {@code attributeName} is a class,
* it will be wrapped in a single-element array before returning it.
* @param attributeName the name of the attribute to get;
* never {@code null} or empty
* @return the value
* @throws IllegalArgumentException if the attribute does not exist or
* if it is not of the expected type
@@ -361,8 +356,8 @@ public class AnnotationAttributes extends LinkedHashMap<String, Object> {
/**
* Get the annotation of type {@code annotationType} stored under the
* specified {@code attributeName}.
* @param attributeName the name of the attribute to get; never
* {@code null} or empty
* @param attributeName the name of the attribute to get;
* never {@code null} or empty
* @param annotationType the expected annotation type; never {@code null}
* @return the annotation
* @throws IllegalArgumentException if the attribute does not exist or
@@ -381,8 +376,8 @@ public class AnnotationAttributes extends LinkedHashMap<String, Object> {
* a single-element array before returning it.
* <p>Note: if you expect an actual array of annotations, invoke
* {@link #getAnnotationArray(String, Class)} instead.
* @param attributeName the name of the attribute to get; never
* {@code null} or empty
* @param attributeName the name of the attribute to get;
* never {@code null} or empty
* @return the array of {@code AnnotationAttributes}
* @throws IllegalArgumentException if the attribute does not exist or
* if it is not of the expected type
@@ -397,8 +392,8 @@ public class AnnotationAttributes extends LinkedHashMap<String, Object> {
* <p>If the value stored under the specified {@code attributeName} is
* an {@code Annotation}, it will be wrapped in a single-element array
* before returning it.
* @param attributeName the name of the attribute to get; never
* {@code null} or empty
* @param attributeName the name of the attribute to get;
* never {@code null} or empty
* @param annotationType the expected annotation type; never {@code null}
* @return the annotation array
* @throws IllegalArgumentException if the attribute does not exist or
@@ -419,8 +414,8 @@ public class AnnotationAttributes extends LinkedHashMap<String, Object> {
* component type of the expected array type, the single element will be
* wrapped in a single-element array of the appropriate type before
* returning it.
* @param attributeName the name of the attribute to get; never
* {@code null} or empty
* @param attributeName the name of the attribute to get;
* never {@code null} or empty
* @param expectedType the expected type; never {@code null}
* @return the value
* @throws IllegalArgumentException if the attribute does not exist or

View File

@@ -207,8 +207,8 @@ public final class Property {
}
private void addAnnotationsToMap(
Map<Class<? extends Annotation>, Annotation> annotationMap,
AnnotatedElement object) {
Map<Class<? extends Annotation>, Annotation> annotationMap, AnnotatedElement object) {
if (object != null) {
for (Annotation annotation : object.getAnnotations()) {
annotationMap.put(annotation.annotationType(), annotation);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -112,6 +112,10 @@ final class ByteBufferConverter implements ConditionalGenericConverter {
byte[] bytes = (byte[]) (source instanceof byte[] ? source :
this.conversionService.convert(source, sourceType, BYTE_ARRAY_TYPE));
if (bytes == null) {
return ByteBuffer.wrap(new byte[0]);
}
ByteBuffer byteBuffer = ByteBuffer.allocate(bytes.length);
byteBuffer.put(bytes);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -40,10 +40,12 @@ final class CollectionToArrayConverter implements ConditionalGenericConverter {
private final ConversionService conversionService;
public CollectionToArrayConverter(ConversionService conversionService) {
this.conversionService = conversionService;
}
@Override
public Set<ConvertiblePair> getConvertibleTypes() {
return Collections.singleton(new ConvertiblePair(Collection.class, Object[].class));
@@ -51,7 +53,8 @@ final class CollectionToArrayConverter implements ConditionalGenericConverter {
@Override
public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
return ConversionUtils.canConvertElements(sourceType.getElementTypeDescriptor(), targetType.getElementTypeDescriptor(), this.conversionService);
return ConversionUtils.canConvertElements(sourceType.getElementTypeDescriptor(),
targetType.getElementTypeDescriptor(), this.conversionService);
}
@Override
@@ -63,7 +66,8 @@ final class CollectionToArrayConverter implements ConditionalGenericConverter {
Object array = Array.newInstance(targetType.getElementTypeDescriptor().getType(), sourceCollection.size());
int i = 0;
for (Object sourceElement : sourceCollection) {
Object targetElement = this.conversionService.convert(sourceElement, sourceType.elementTypeDescriptor(sourceElement), targetType.getElementTypeDescriptor());
Object targetElement = this.conversionService.convert( sourceElement,
sourceType.elementTypeDescriptor(sourceElement), targetType.getElementTypeDescriptor());
Array.set(array, i++, targetElement);
}
return array;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -50,10 +50,9 @@ abstract class ReadOnlySystemAttributesMap implements Map<String, String> {
public String get(Object key) {
if (!(key instanceof String)) {
throw new IllegalArgumentException(
"Type of key [" + (key != null ? key.getClass().getName() : "null") +
"] must be java.lang.String.");
"Type of key [" + key.getClass().getName() + "] must be java.lang.String");
}
return this.getSystemAttribute((String) key);
return getSystemAttribute((String) key);
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,6 +21,8 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import org.springframework.util.Assert;
/**
* {@link Resource} implementation for a given byte array.
* <p>Creates a {@link ByteArrayInputStream} for the given byte array.
@@ -58,9 +60,7 @@ public class ByteArrayResource extends AbstractResource {
* @param description where the byte array comes from
*/
public ByteArrayResource(byte[] byteArray, String description) {
if (byteArray == null) {
throw new IllegalArgumentException("Byte array must not be null");
}
Assert.notNull(byteArray, "Byte array must not be null");
this.byteArray = byteArray;
this.description = (description != null ? description : "");
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -46,10 +46,10 @@ public abstract class VfsUtils {
private static final String VFS3_PKG = "org.jboss.vfs.";
private static final String VFS_NAME = "VFS";
private static Method VFS_METHOD_GET_ROOT_URL = null;
private static Method VFS_METHOD_GET_ROOT_URI = null;
private static Method VFS_METHOD_GET_ROOT_URL;
private static Method VFS_METHOD_GET_ROOT_URI;
private static Method VIRTUAL_FILE_METHOD_EXISTS = null;
private static Method VIRTUAL_FILE_METHOD_EXISTS;
private static Method VIRTUAL_FILE_METHOD_GET_INPUT_STREAM;
private static Method VIRTUAL_FILE_METHOD_GET_SIZE;
private static Method VIRTUAL_FILE_METHOD_GET_LAST_MODIFIED;
@@ -62,8 +62,8 @@ public abstract class VfsUtils {
protected static Class<?> VIRTUAL_FILE_VISITOR_INTERFACE;
protected static Method VIRTUAL_FILE_METHOD_VISIT;
private static Field VISITOR_ATTRIBUTES_FIELD_RECURSE = null;
private static Method GET_PHYSICAL_FILE = null;
private static Field VISITOR_ATTRIBUTES_FIELD_RECURSE;
private static Method GET_PHYSICAL_FILE;
static {
ClassLoader loader = VfsUtils.class.getClassLoader();
@@ -90,7 +90,7 @@ public abstract class VfsUtils {
Class<?> visitorAttributesClass = loader.loadClass(VFS3_PKG + "VisitorAttributes");
VISITOR_ATTRIBUTES_FIELD_RECURSE = ReflectionUtils.findField(visitorAttributesClass, "RECURSE");
}
catch (ClassNotFoundException ex) {
catch (Throwable ex) {
throw new IllegalStateException("Could not detect JBoss VFS infrastructure", ex);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -404,12 +404,6 @@ public class FastByteArrayOutputStream extends OutputStream {
else if (len == 0) {
return 0;
}
else if (len < 0) {
throw new IllegalArgumentException("len must be 0 or greater: " + len);
}
else if (off < 0) {
throw new IllegalArgumentException("off must be 0 or greater: " + off);
}
else {
if (this.currentBuffer == null) {
// This stream doesn't have any data in it...

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -122,8 +122,8 @@ public class MethodInvoker {
* Set arguments for the method invocation. If this property is not set,
* or the Object array is of length 0, a method with no arguments is assumed.
*/
public void setArguments(Object[] arguments) {
this.arguments = (arguments != null ? arguments : new Object[0]);
public void setArguments(Object... arguments) {
this.arguments = arguments;
}
/**
@@ -156,12 +156,8 @@ public class MethodInvoker {
Class<?> targetClass = getTargetClass();
String targetMethod = getTargetMethod();
if (targetClass == null) {
throw new IllegalArgumentException("Either 'targetClass' or 'targetObject' is required");
}
if (targetMethod == null) {
throw new IllegalArgumentException("Property 'targetMethod' is required");
}
Assert.notNull(targetClass, "Either 'targetClass' or 'targetObject' is required");
Assert.notNull(targetMethod, "Property 'targetMethod' is required");
Object[] arguments = getArguments();
Class<?>[] argTypes = new Class<?>[arguments.length];

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -724,12 +724,8 @@ public abstract class ReflectionUtils {
* work on objects with public no-arg constructors.
*/
public static void shallowCopyFieldState(final Object src, final Object dest) {
if (src == null) {
throw new IllegalArgumentException("Source for field copy cannot be null");
}
if (dest == null) {
throw new IllegalArgumentException("Destination for field copy cannot be null");
}
Assert.notNull(src, "Source for field copy cannot be null");
Assert.notNull(dest, "Destination for field copy cannot be null");
if (!src.getClass().isAssignableFrom(dest.getClass())) {
throw new IllegalArgumentException("Destination class [" + dest.getClass().getName() +
"] must be same or subclass as source class [" + src.getClass().getName() + "]");

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -215,7 +215,6 @@ public abstract class TypeUtils {
if (rhsType == null) {
return true;
}
if (lhsType == null) {
return false;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -49,7 +49,7 @@ public abstract class FutureAdapter<T, S> implements Future<T> {
* @param adaptee the future to delegate to
*/
protected FutureAdapter(Future<S> adaptee) {
Assert.notNull(adaptee, "'delegate' must not be null");
Assert.notNull(adaptee, "Delegate must not be null");
this.adaptee = adaptee;
}