Make getters and setters null-safety consistent

This commit ensure that null-safety is consistent between
getters and setters in order to be able to provide beans
with properties with a common type when type safety is
taken in account like with Kotlin.

It also add a few missing property level @Nullable
annotations.

Issue: SPR-15792
This commit is contained in:
Sebastien Deleuze
2017-07-19 08:55:05 +02:00
parent ff85726fa9
commit fb4ddb0746
201 changed files with 579 additions and 489 deletions

View File

@@ -292,7 +292,7 @@ class ExtendedBeanInfo implements BeanInfo {
}
@Override
public void setReadMethod(Method readMethod) {
public void setReadMethod(@Nullable Method readMethod) {
this.readMethod = readMethod;
}
@@ -303,7 +303,7 @@ class ExtendedBeanInfo implements BeanInfo {
}
@Override
public void setWriteMethod(Method writeMethod) {
public void setWriteMethod(@Nullable Method writeMethod) {
this.writeMethod = writeMethod;
}
@@ -327,7 +327,7 @@ class ExtendedBeanInfo implements BeanInfo {
}
@Override
public void setPropertyEditorClass(Class<?> propertyEditorClass) {
public void setPropertyEditorClass(@Nullable Class<?> propertyEditorClass) {
this.propertyEditorClass = propertyEditorClass;
}
@@ -399,7 +399,7 @@ class ExtendedBeanInfo implements BeanInfo {
}
@Override
public void setReadMethod(Method readMethod) {
public void setReadMethod(@Nullable Method readMethod) {
this.readMethod = readMethod;
}
@@ -410,7 +410,7 @@ class ExtendedBeanInfo implements BeanInfo {
}
@Override
public void setWriteMethod(Method writeMethod) {
public void setWriteMethod(@Nullable Method writeMethod) {
this.writeMethod = writeMethod;
}
@@ -434,7 +434,7 @@ class ExtendedBeanInfo implements BeanInfo {
}
@Override
public void setIndexedReadMethod(Method indexedReadMethod) throws IntrospectionException {
public void setIndexedReadMethod(@Nullable Method indexedReadMethod) throws IntrospectionException {
this.indexedReadMethod = indexedReadMethod;
}
@@ -445,7 +445,7 @@ class ExtendedBeanInfo implements BeanInfo {
}
@Override
public void setIndexedWriteMethod(Method indexedWriteMethod) throws IntrospectionException {
public void setIndexedWriteMethod(@Nullable Method indexedWriteMethod) throws IntrospectionException {
this.indexedWriteMethod = indexedWriteMethod;
}
@@ -470,7 +470,7 @@ class ExtendedBeanInfo implements BeanInfo {
}
@Override
public void setPropertyEditorClass(Class<?> propertyEditorClass) {
public void setPropertyEditorClass(@Nullable Class<?> propertyEditorClass) {
this.propertyEditorClass = propertyEditorClass;
}

View File

@@ -101,7 +101,7 @@ public abstract class AbstractFactoryBean<T>
}
@Override
public void setBeanFactory(BeanFactory beanFactory) {
public void setBeanFactory(@Nullable BeanFactory beanFactory) {
this.beanFactory = beanFactory;
}

View File

@@ -148,7 +148,7 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement {
* Set the names of the beans that this bean depends on being initialized.
* The bean factory will guarantee that these beans get initialized first.
*/
void setDependsOn(String... dependsOn);
void setDependsOn(@Nullable String... dependsOn);
/**
* Return the bean names that this bean depends on.

View File

@@ -554,8 +554,8 @@ public class ConstructorArgumentValues {
* Set the converted value of the constructor argument,
* after processed type conversion.
*/
public synchronized void setConvertedValue(Object value) {
this.converted = true;
public synchronized void setConvertedValue(@Nullable Object value) {
this.converted = (value != null);
this.convertedValue = value;
}

View File

@@ -87,7 +87,7 @@ public class FieldRetrievingFactoryBean
* @see #setTargetObject
* @see #setTargetField
*/
public void setTargetClass(Class<?> targetClass) {
public void setTargetClass(@Nullable Class<?> targetClass) {
this.targetClass = targetClass;
}
@@ -106,7 +106,7 @@ public class FieldRetrievingFactoryBean
* @see #setTargetClass
* @see #setTargetField
*/
public void setTargetObject(Object targetObject) {
public void setTargetObject(@Nullable Object targetObject) {
this.targetObject = targetObject;
}
@@ -125,7 +125,7 @@ public class FieldRetrievingFactoryBean
* @see #setTargetClass
* @see #setTargetObject
*/
public void setTargetField(String targetField) {
public void setTargetField(@Nullable String targetField) {
this.targetField = StringUtils.trimAllWhitespace(targetField);
}

View File

@@ -126,8 +126,7 @@ public class TypedStringValue implements BeanMetadataElement {
/**
* Specify the type to convert to.
*/
public void setTargetTypeName(String targetTypeName) {
Assert.notNull(targetTypeName, "'targetTypeName' must not be null");
public void setTargetTypeName(@Nullable String targetTypeName) {
this.targetType = targetTypeName;
}

View File

@@ -45,7 +45,7 @@ public abstract class AbstractServiceLoaderBasedFactoryBean extends AbstractFact
/**
* Specify the desired service type (typically the service's public API).
*/
public void setServiceType(Class<?> serviceType) {
public void setServiceType(@Nullable Class<?> serviceType) {
this.serviceType = serviceType;
}

View File

@@ -122,7 +122,7 @@ public abstract class AbstractBeanDefinitionReader implements EnvironmentCapable
* @see org.springframework.core.io.support.ResourcePatternResolver
* @see org.springframework.core.io.support.PathMatchingResourcePatternResolver
*/
public void setResourceLoader(ResourceLoader resourceLoader) {
public void setResourceLoader(@Nullable ResourceLoader resourceLoader) {
this.resourceLoader = resourceLoader;
}

View File

@@ -268,7 +268,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
* @see org.springframework.core.OrderComparator
* @see org.springframework.core.annotation.AnnotationAwareOrderComparator
*/
public void setDependencyComparator(Comparator<Object> dependencyComparator) {
public void setDependencyComparator(@Nullable Comparator<Object> dependencyComparator) {
this.dependencyComparator = dependencyComparator;
}

View File

@@ -71,7 +71,7 @@ public class ManagedMap<K, V> extends LinkedHashMap<K, V> implements Mergeable,
/**
* Set the default key type name (class name) to be used for this map.
*/
public void setKeyTypeName(String keyTypeName) {
public void setKeyTypeName(@Nullable String keyTypeName) {
this.keyTypeName = keyTypeName;
}
@@ -86,7 +86,7 @@ public class ManagedMap<K, V> extends LinkedHashMap<K, V> implements Mergeable,
/**
* Set the default value type name (class name) to be used for this map.
*/
public void setValueTypeName(String valueTypeName) {
public void setValueTypeName(@Nullable String valueTypeName) {
this.valueTypeName = valueTypeName;
}

View File

@@ -68,7 +68,7 @@ public class ManagedSet<E> extends LinkedHashSet<E> implements Mergeable, BeanMe
/**
* Set the default element type name (class name) to be used for this set.
*/
public void setElementTypeName(String elementTypeName) {
public void setElementTypeName(@Nullable String elementTypeName) {
this.elementTypeName = elementTypeName;
}

View File

@@ -257,7 +257,7 @@ public class RootBeanDefinition extends AbstractBeanDefinition {
/**
* Register a target definition that is being decorated by this bean definition.
*/
public void setDecoratedDefinition(BeanDefinitionHolder decoratedDefinition) {
public void setDecoratedDefinition(@Nullable BeanDefinitionHolder decoratedDefinition) {
this.decoratedDefinition = decoratedDefinition;
}
@@ -276,7 +276,7 @@ public class RootBeanDefinition extends AbstractBeanDefinition {
* @see #setTargetType(ResolvableType)
* @see #getResolvedFactoryMethod()
*/
public void setQualifiedElement(AnnotatedElement qualifiedElement) {
public void setQualifiedElement(@Nullable AnnotatedElement qualifiedElement) {
this.qualifiedElement = qualifiedElement;
}

View File

@@ -55,9 +55,9 @@ public class ArgumentConvertingMethodInvoker extends MethodInvoker {
* @see org.springframework.beans.SimpleTypeConverter
* @see org.springframework.beans.BeanWrapperImpl
*/
public void setTypeConverter(TypeConverter typeConverter) {
public void setTypeConverter(@Nullable TypeConverter typeConverter) {
this.typeConverter = typeConverter;
this.useDefaultConverter = false;
this.useDefaultConverter = (typeConverter == null);
}
/**