Add more @Nullable parameters based on null usage

Issue: SPR-15540
This commit is contained in:
Sebastien Deleuze
2017-05-31 21:35:52 +02:00
parent f9b319d3ba
commit 1f28825f9d
219 changed files with 441 additions and 355 deletions

View File

@@ -189,7 +189,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
* @param nestedPath the nested path of the object
* @param rootObject the root object at the top of the path
*/
public void setWrappedInstance(Object object, String nestedPath, Object rootObject) {
public void setWrappedInstance(Object object, String nestedPath, @Nullable Object rootObject) {
this.wrappedObject = ObjectUtils.unwrapOptional(object);
Assert.notNull(this.wrappedObject, "Target object must not be null");
this.nestedPath = (nestedPath != null ? nestedPath : "");
@@ -567,7 +567,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
return false;
}
private Object convertIfNecessary(String propertyName, Object oldValue, Object newValue, Class<?> requiredType,
private Object convertIfNecessary(@Nullable String propertyName, @Nullable Object oldValue, Object newValue, Class<?> requiredType,
TypeDescriptor td) throws TypeMismatchException {
try {
return this.typeConverterDelegate.convertIfNecessary(propertyName, oldValue, newValue, requiredType, td);
@@ -594,7 +594,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
}
}
protected Object convertForProperty(String propertyName, Object oldValue, Object newValue, TypeDescriptor td)
protected Object convertForProperty(String propertyName, @Nullable Object oldValue, Object newValue, TypeDescriptor td)
throws TypeMismatchException {
return convertIfNecessary(propertyName, oldValue, newValue, td.getType(), td);
@@ -886,7 +886,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
return new PropertyValue(tokens.canonicalName, defaultValue);
}
private Object newValue(Class<?> type, TypeDescriptor desc, String name) {
private Object newValue(Class<?> type, @Nullable TypeDescriptor desc, String name) {
try {
if (type.isArray()) {
Class<?> componentType = type.getComponentType();

View File

@@ -599,7 +599,7 @@ public abstract class BeanUtils {
* @throws BeansException if the copying failed
* @see BeanWrapper
*/
private static void copyProperties(Object source, Object target, Class<?> editable, String... ignoreProperties)
private static void copyProperties(Object source, Object target, @Nullable Class<?> editable, String... ignoreProperties)
throws BeansException {
Assert.notNull(source, "Source must not be null");

View File

@@ -28,6 +28,7 @@ import java.security.PrivilegedExceptionAction;
import org.springframework.core.ResolvableType;
import org.springframework.core.convert.Property;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -147,7 +148,7 @@ public class BeanWrapperImpl extends AbstractNestablePropertyAccessor implements
}
@Override
public void setWrappedInstance(Object object, String nestedPath, Object rootObject) {
public void setWrappedInstance(Object object, String nestedPath, @Nullable Object rootObject) {
super.setWrappedInstance(object, nestedPath, rootObject);
setIntrospectionClass(getWrappedClass());
}

View File

@@ -280,7 +280,7 @@ class ExtendedBeanInfo implements BeanInfo {
PropertyDescriptorUtils.copyNonMethodProperties(original, this);
}
public SimplePropertyDescriptor(String propertyName, Method readMethod, Method writeMethod) throws IntrospectionException {
public SimplePropertyDescriptor(String propertyName, @Nullable Method readMethod, Method writeMethod) throws IntrospectionException {
super(propertyName, null, null);
this.readMethod = readMethod;
this.writeMethod = writeMethod;
@@ -371,8 +371,8 @@ class ExtendedBeanInfo implements BeanInfo {
PropertyDescriptorUtils.copyNonMethodProperties(original, this);
}
public SimpleIndexedPropertyDescriptor(String propertyName, Method readMethod, Method writeMethod,
Method indexedReadMethod, Method indexedWriteMethod) throws IntrospectionException {
public SimpleIndexedPropertyDescriptor(String propertyName, @Nullable Method readMethod, @Nullable Method writeMethod,
@Nullable Method indexedReadMethod, Method indexedWriteMethod) throws IntrospectionException {
super(propertyName, null, null, null, null);
this.readMethod = readMethod;

View File

@@ -145,7 +145,7 @@ class TypeConverterDelegate {
* @throws IllegalArgumentException if type conversion failed
*/
@SuppressWarnings("unchecked")
public <T> T convertIfNecessary(String propertyName, @Nullable Object oldValue, Object newValue,
public <T> T convertIfNecessary(@Nullable String propertyName, @Nullable Object oldValue, Object newValue,
@Nullable Class<T> requiredType, TypeDescriptor typeDescriptor) throws IllegalArgumentException {
// Custom editor for this type?

View File

@@ -339,7 +339,7 @@ public interface AutowireCapableBeanFactory extends BeanFactory {
* @see #resolveDependency(DependencyDescriptor, String, Set, TypeConverter)
*/
@Nullable
Object resolveDependency(DependencyDescriptor descriptor, String requestingBeanName) throws BeansException;
Object resolveDependency(DependencyDescriptor descriptor, @Nullable String requestingBeanName) throws BeansException;
/**
* Resolve the specified dependency against the beans defined in this factory.
@@ -357,6 +357,6 @@ public interface AutowireCapableBeanFactory extends BeanFactory {
*/
@Nullable
Object resolveDependency(DependencyDescriptor descriptor, String requestingBeanName,
Set<String> autowiredBeanNames, TypeConverter typeConverter) throws BeansException;
@Nullable Set<String> autowiredBeanNames, @Nullable TypeConverter typeConverter) throws BeansException;
}

View File

@@ -32,7 +32,7 @@ public class BeanExpressionContext {
private final Scope scope;
public BeanExpressionContext(ConfigurableBeanFactory beanFactory, Scope scope) {
public BeanExpressionContext(ConfigurableBeanFactory beanFactory, @Nullable Scope scope) {
Assert.notNull(beanFactory, "BeanFactory must not be null");
this.beanFactory = beanFactory;
this.scope = scope;

View File

@@ -102,7 +102,7 @@ public interface ConfigurableBeanFactory extends HierarchicalBeanFactory, Single
* then removed once the BeanFactory completes its bootstrap phase.
* @since 2.5
*/
void setTempClassLoader(ClassLoader tempClassLoader);
void setTempClassLoader(@Nullable ClassLoader tempClassLoader);
/**
* Return the temporary ClassLoader to use for type matching purposes,

View File

@@ -279,7 +279,7 @@ public class ConstructorArgumentValues {
* @return the ValueHolder for the argument, or {@code null} if none found
*/
@Nullable
public ValueHolder getGenericArgumentValue(@Nullable Class<?> requiredType, @Nullable String requiredName, Set<ValueHolder> usedValueHolders) {
public ValueHolder getGenericArgumentValue(@Nullable Class<?> requiredType, @Nullable String requiredName, @Nullable Set<ValueHolder> usedValueHolders) {
for (ValueHolder valueHolder : this.genericArgumentValues) {
if (usedValueHolders != null && usedValueHolders.contains(valueHolder)) {
continue;
@@ -351,7 +351,7 @@ public class ConstructorArgumentValues {
* @return the ValueHolder for the argument, or {@code null} if none set
*/
@Nullable
public ValueHolder getArgumentValue(int index, @Nullable Class<?> requiredType, @Nullable String requiredName, Set<ValueHolder> usedValueHolders) {
public ValueHolder getArgumentValue(int index, @Nullable Class<?> requiredType, @Nullable String requiredName, @Nullable Set<ValueHolder> usedValueHolders) {
Assert.isTrue(index >= 0, "Index must not be negative");
ValueHolder valueHolder = getIndexedArgumentValue(index, requiredType, requiredName);
if (valueHolder == null) {

View File

@@ -52,7 +52,7 @@ public class TypedStringValue implements BeanMetadataElement {
* Create a new {@link TypedStringValue} for the given String value.
* @param value the String value
*/
public TypedStringValue(String value) {
public TypedStringValue(@Nullable String value) {
setValue(value);
}
@@ -62,7 +62,7 @@ public class TypedStringValue implements BeanMetadataElement {
* @param value the String value
* @param targetType the type to convert to
*/
public TypedStringValue(String value, Class<?> targetType) {
public TypedStringValue(@Nullable String value, Class<?> targetType) {
setValue(value);
setTargetType(targetType);
}
@@ -73,7 +73,7 @@ public class TypedStringValue implements BeanMetadataElement {
* @param value the String value
* @param targetTypeName the type to convert to
*/
public TypedStringValue(String value, String targetTypeName) {
public TypedStringValue(@Nullable String value, String targetTypeName) {
setValue(value);
setTargetTypeName(targetTypeName);
}
@@ -85,13 +85,14 @@ public class TypedStringValue implements BeanMetadataElement {
* for example in BeanFactoryPostProcessors.
* @see PropertyPlaceholderConfigurer
*/
public void setValue(String value) {
public void setValue(@Nullable String value) {
this.value = value;
}
/**
* Return the String value.
*/
@Nullable
public String getValue() {
return this.value;
}

View File

@@ -39,6 +39,7 @@ import org.yaml.snakeyaml.reader.UnicodeReader;
import org.springframework.core.CollectionFactory;
import org.springframework.core.io.Resource;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
@@ -272,7 +273,7 @@ public abstract class YamlProcessor {
return result;
}
private void buildFlattenedMap(Map<String, Object> result, Map<String, Object> source, String path) {
private void buildFlattenedMap(Map<String, Object> result, Map<String, Object> source, @Nullable String path) {
for (Entry<String, Object> entry : source.entrySet()) {
String key = entry.getKey();
if (StringUtils.hasText(path)) {

View File

@@ -67,7 +67,7 @@ public class Problem {
* @param parseState the {@link ParseState} at the time of the error
* @param location the location within a bean configuration source that triggered the error
*/
public Problem(String message, Location location, ParseState parseState, @Nullable Throwable rootCause) {
public Problem(String message, Location location, @Nullable ParseState parseState, @Nullable Throwable rootCause) {
Assert.notNull(message, "Message must not be null");
Assert.notNull(location, "Location must not be null");
this.message = message;

View File

@@ -17,6 +17,7 @@
package org.springframework.beans.factory.parsing;
import org.springframework.core.io.Resource;
import org.springframework.lang.Nullable;
/**
* Context that gets passed along a bean definition reading process,
@@ -59,11 +60,11 @@ public class ReaderContext {
fatal(message, source, null, ex);
}
public void fatal(String message, Object source, ParseState parseState) {
public void fatal(String message, Object source, @Nullable ParseState parseState) {
fatal(message, source, parseState, null);
}
public void fatal(String message, Object source, ParseState parseState, Throwable cause) {
public void fatal(String message, Object source, @Nullable ParseState parseState, @Nullable Throwable cause) {
Location location = new Location(getResource(), source);
this.problemReporter.fatal(new Problem(message, location, parseState, cause));
}
@@ -72,15 +73,15 @@ public class ReaderContext {
error(message, source, null, null);
}
public void error(String message, Object source, Throwable ex) {
public void error(String message, Object source, @Nullable Throwable ex) {
error(message, source, null, ex);
}
public void error(String message, Object source, ParseState parseState) {
public void error(String message, Object source, @Nullable ParseState parseState) {
error(message, source, parseState, null);
}
public void error(String message, Object source, ParseState parseState, Throwable cause) {
public void error(String message, Object source, @Nullable ParseState parseState, @Nullable Throwable cause) {
Location location = new Location(getResource(), source);
this.problemReporter.error(new Problem(message, location, parseState, cause));
}
@@ -89,15 +90,15 @@ public class ReaderContext {
warning(message, source, null, null);
}
public void warning(String message, Object source, Throwable ex) {
public void warning(String message, Object source, @Nullable Throwable ex) {
warning(message, source, null, ex);
}
public void warning(String message, Object source, ParseState parseState) {
public void warning(String message, Object source, @Nullable ParseState parseState) {
warning(message, source, parseState, null);
}
public void warning(String message, Object source, ParseState parseState, Throwable cause) {
public void warning(String message, Object source, @Nullable ParseState parseState, @Nullable Throwable cause) {
Location location = new Location(getResource(), source);
this.problemReporter.warning(new Problem(message, location, parseState, cause));
}

View File

@@ -334,7 +334,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
}
@Override
public Object resolveDependency(DependencyDescriptor descriptor, String requestingBeanName) throws BeansException {
public Object resolveDependency(DependencyDescriptor descriptor, @Nullable String requestingBeanName) throws BeansException {
return resolveDependency(descriptor, requestingBeanName, null, null);
}
@@ -452,7 +452,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
* @see #doCreateBean
*/
@Override
protected Object createBean(String beanName, RootBeanDefinition mbd, Object[] args) throws BeanCreationException {
protected Object createBean(String beanName, RootBeanDefinition mbd, @Nullable Object[] args) throws BeanCreationException {
if (logger.isDebugEnabled()) {
logger.debug("Creating instance of bean '" + beanName + "'");
}
@@ -1084,7 +1084,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
* @see #autowireConstructor
* @see #instantiateBean
*/
protected BeanWrapper createBeanInstance(String beanName, RootBeanDefinition mbd, Object[] args) {
protected BeanWrapper createBeanInstance(String beanName, RootBeanDefinition mbd, @Nullable Object[] args) {
// Make sure bean class is actually resolved at this point.
Class<?> beanClass = resolveBeanClass(mbd, beanName);
@@ -1271,7 +1271,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
* @return a BeanWrapper for the new instance
*/
protected BeanWrapper autowireConstructor(
String beanName, RootBeanDefinition mbd, Constructor<?>[] ctors, @Nullable Object[] explicitArgs) {
String beanName, RootBeanDefinition mbd, @Nullable Constructor<?>[] ctors, @Nullable Object[] explicitArgs) {
return new ConstructorResolver(this).autowireConstructor(beanName, mbd, ctors, explicitArgs);
}

View File

@@ -230,7 +230,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
*/
@SuppressWarnings("unchecked")
protected <T> T doGetBean(
final String name, final Class<T> requiredType, final Object[] args, boolean typeCheckOnly)
final String name, @Nullable final Class<T> requiredType, @Nullable final Object[] args, boolean typeCheckOnly)
throws BeansException {
final String beanName = transformedBeanName(name);
@@ -708,7 +708,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
}
@Override
public void setTempClassLoader(ClassLoader tempClassLoader) {
public void setTempClassLoader(@Nullable ClassLoader tempClassLoader) {
this.tempClassLoader = tempClassLoader;
}

View File

@@ -20,6 +20,7 @@ import java.util.function.Supplier;
import org.springframework.beans.factory.config.BeanDefinitionCustomizer;
import org.springframework.beans.factory.config.RuntimeBeanReference;
import org.springframework.lang.Nullable;
import org.springframework.util.ObjectUtils;
/**
@@ -93,7 +94,7 @@ public class BeanDefinitionBuilder {
* @param beanClassName the class name for the bean that the definition is being created for
* @param factoryMethodName the name of the method to use to construct the bean instance
*/
public static BeanDefinitionBuilder rootBeanDefinition(String beanClassName, String factoryMethodName) {
public static BeanDefinitionBuilder rootBeanDefinition(String beanClassName, @Nullable String factoryMethodName) {
BeanDefinitionBuilder builder = new BeanDefinitionBuilder();
builder.beanDefinition = new RootBeanDefinition();
builder.beanDefinition.setBeanClassName(beanClassName);
@@ -114,7 +115,7 @@ public class BeanDefinitionBuilder {
* @param beanClass the {@code Class} of the bean that the definition is being created for
* @param factoryMethodName the name of the method to use to construct the bean instance
*/
public static BeanDefinitionBuilder rootBeanDefinition(Class<?> beanClass, String factoryMethodName) {
public static BeanDefinitionBuilder rootBeanDefinition(Class<?> beanClass, @Nullable String factoryMethodName) {
BeanDefinitionBuilder builder = new BeanDefinitionBuilder();
builder.beanDefinition = new RootBeanDefinition();
builder.beanDefinition.setBeanClass(beanClass);

View File

@@ -78,7 +78,7 @@ public class CglibSubclassingInstantiationStrategy extends SimpleInstantiationSt
@Override
protected Object instantiateWithMethodInjection(RootBeanDefinition bd, String beanName, BeanFactory owner,
Constructor<?> ctor, Object... args) {
@Nullable Constructor<?> ctor, Object... args) {
// Must generate CGLIB subclass...
return new CglibSubclassCreator(bd, owner).instantiate(ctor, args);

View File

@@ -823,7 +823,7 @@ class ConstructorResolver {
* Template method for resolving the specified argument which is supposed to be autowired.
*/
protected Object resolveAutowiredArgument(
MethodParameter param, String beanName, Set<String> autowiredBeanNames, TypeConverter typeConverter) {
MethodParameter param, String beanName, @Nullable Set<String> autowiredBeanNames, TypeConverter typeConverter) {
if (InjectionPoint.class.isAssignableFrom(param.getParameterType())) {
InjectionPoint injectionPoint = currentInjectionPoint.get();

View File

@@ -1040,7 +1040,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
@Override
public Object resolveDependency(DependencyDescriptor descriptor, String requestingBeanName,
Set<String> autowiredBeanNames, TypeConverter typeConverter) throws BeansException {
@Nullable Set<String> autowiredBeanNames, @Nullable TypeConverter typeConverter) throws BeansException {
descriptor.initParameterNameDiscovery(getParameterNameDiscoverer());
if (Optional.class == descriptor.getDependencyType()) {
@@ -1065,7 +1065,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
@Nullable
public Object doResolveDependency(DependencyDescriptor descriptor, String beanName,
Set<String> autowiredBeanNames, TypeConverter typeConverter) throws BeansException {
@Nullable Set<String> autowiredBeanNames, @Nullable TypeConverter typeConverter) throws BeansException {
InjectionPoint previousInjectionPoint = ConstructorResolver.setCurrentInjectionPoint(descriptor);
try {

View File

@@ -450,7 +450,7 @@ public class DefaultSingletonBeanRegistry extends SimpleAliasRegistry implements
return isDependent(beanName, dependentBeanName, null);
}
private boolean isDependent(String beanName, String dependentBeanName, Set<String> alreadySeen) {
private boolean isDependent(String beanName, String dependentBeanName, @Nullable Set<String> alreadySeen) {
if (alreadySeen != null && alreadySeen.contains(beanName)) {
return false;
}

View File

@@ -178,7 +178,7 @@ public class RootBeanDefinition extends AbstractBeanDefinition {
* @param cargs the constructor argument values to apply
* @param pvs the property values to apply
*/
public RootBeanDefinition(@Nullable Class<?> beanClass, ConstructorArgumentValues cargs, MutablePropertyValues pvs) {
public RootBeanDefinition(@Nullable Class<?> beanClass, ConstructorArgumentValues cargs, @Nullable MutablePropertyValues pvs) {
super(cargs, pvs);
setBeanClass(beanClass);
}

View File

@@ -135,7 +135,7 @@ public class SimpleInstantiationStrategy implements InstantiationStrategy {
* Instantiation should use the given constructor and parameters.
*/
protected Object instantiateWithMethodInjection(RootBeanDefinition bd, String beanName, BeanFactory owner,
Constructor<?> ctor, Object... args) {
@Nullable Constructor<?> ctor, Object... args) {
throw new UnsupportedOperationException("Method Injection not supported in SimpleInstantiationStrategy");
}

View File

@@ -309,7 +309,7 @@ public class BeanDefinitionParserDelegate {
* @see #populateDefaults(DocumentDefaultsDefinition, DocumentDefaultsDefinition, org.w3c.dom.Element)
* @see #getDefaults()
*/
public void initDefaults(Element root, BeanDefinitionParserDelegate parent) {
public void initDefaults(Element root, @Nullable BeanDefinitionParserDelegate parent) {
populateDefaults(this.defaults, (parent != null ? parent.defaults : null), root);
this.readerContext.fireDefaultsRegistered(this.defaults);
}
@@ -417,7 +417,7 @@ public class BeanDefinitionParserDelegate {
* {@link org.springframework.beans.factory.parsing.ProblemReporter}.
*/
@Nullable
public BeanDefinitionHolder parseBeanDefinitionElement(Element ele, BeanDefinition containingBean) {
public BeanDefinitionHolder parseBeanDefinitionElement(Element ele, @Nullable BeanDefinition containingBean) {
String id = ele.getAttribute(ID_ATTRIBUTE);
String nameAttr = ele.getAttribute(NAME_ATTRIBUTE);
@@ -907,7 +907,7 @@ public class BeanDefinitionParserDelegate {
* Also used for constructor arguments, "propertyName" being null in this case.
*/
@Nullable
public Object parsePropertyValue(Element ele, BeanDefinition bd, String propertyName) {
public Object parsePropertyValue(Element ele, BeanDefinition bd, @Nullable String propertyName) {
String elementName = (propertyName != null) ?
"<property> element for property '" + propertyName + "'" :
"<constructor-arg> element";
@@ -961,7 +961,7 @@ public class BeanDefinitionParserDelegate {
}
}
public Object parsePropertySubElement(Element ele, BeanDefinition bd) {
public Object parsePropertySubElement(Element ele, @Nullable BeanDefinition bd) {
return parsePropertySubElement(ele, bd, null);
}
@@ -973,7 +973,7 @@ public class BeanDefinitionParserDelegate {
* {@code <value>} tag that might be created
*/
@Nullable
public Object parsePropertySubElement(Element ele, BeanDefinition bd, String defaultValueType) {
public Object parsePropertySubElement(Element ele, BeanDefinition bd, @Nullable String defaultValueType) {
if (!isDefaultNamespace(ele)) {
return parseNestedCustomElement(ele, bd);
}
@@ -1355,7 +1355,7 @@ public class BeanDefinitionParserDelegate {
}
@Nullable
public BeanDefinition parseCustomElement(Element ele, BeanDefinition containingBd) {
public BeanDefinition parseCustomElement(Element ele, @Nullable BeanDefinition containingBd) {
String namespaceUri = getNamespaceURI(ele);
NamespaceHandler handler = this.readerContext.getNamespaceHandlerResolver().resolve(namespaceUri);
if (handler == null) {
@@ -1370,7 +1370,7 @@ public class BeanDefinitionParserDelegate {
}
public BeanDefinitionHolder decorateBeanDefinitionIfRequired(
Element ele, BeanDefinitionHolder definitionHolder, BeanDefinition containingBd) {
Element ele, BeanDefinitionHolder definitionHolder, @Nullable BeanDefinition containingBd) {
BeanDefinitionHolder finalDefinition = definitionHolder;