Skip to content

Commit

Permalink
Make getters and setters null-safety consistent
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sdeleuze committed Jul 19, 2017
1 parent ff85726 commit fb4ddb0
Show file tree
Hide file tree
Showing 201 changed files with 579 additions and 489 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class AspectJExpressionPointcutAdvisor extends AbstractGenericPointcutAdv
private final AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();


public void setExpression(String expression) {
public void setExpression(@Nullable String expression) {
this.pointcut.setExpression(expression);
}

Expand All @@ -43,7 +43,7 @@ public String getExpression() {
return this.pointcut.getExpression();
}

public void setLocation(String location) {
public void setLocation(@Nullable String location) {
this.pointcut.setLocation(location);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public void setApplyCommonInterceptorsFirst(boolean applyCommonInterceptorsFirst
}

@Override
public void setBeanFactory(BeanFactory beanFactory) {
public void setBeanFactory(@Nullable BeanFactory beanFactory) {
this.beanFactory = beanFactory;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public boolean isUsePrefix() {
* references. Default value is the bean name of this object + a dot.
* @param advisorBeanNamePrefix the exclusion prefix
*/
public void setAdvisorBeanNamePrefix(String advisorBeanNamePrefix) {
public void setAdvisorBeanNamePrefix(@Nullable String advisorBeanNamePrefix) {
this.advisorBeanNamePrefix = advisorBeanNamePrefix;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public abstract class AbstractBeanFactoryPointcutAdvisor extends AbstractPointcu
* of the advisor.
* @see #getAdvice()
*/
public void setAdviceBeanName(String adviceBeanName) {
public void setAdviceBeanName(@Nullable String adviceBeanName) {
this.adviceBeanName = adviceBeanName;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public abstract class AbstractExpressionPointcut implements ExpressionPointcut,
/**
* Set the location for debugging.
*/
public void setLocation(String location) {
public void setLocation(@Nullable String location) {
this.location = location;
}

Expand All @@ -58,7 +58,7 @@ public String getLocation() {
return this.location;
}

public void setExpression(String expression) {
public void setExpression(@Nullable String expression) {
this.expression = expression;
try {
onSetExpression(expression);
Expand All @@ -82,7 +82,7 @@ public void setExpression(String expression) {
* @throws IllegalArgumentException if the expression is invalid
* @see #setExpression
*/
protected void onSetExpression(String expression) throws IllegalArgumentException {
protected void onSetExpression(@Nullable String expression) throws IllegalArgumentException {
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ public Method getReadMethod() {
}

@Override
public void setReadMethod(Method readMethod) {
public void setReadMethod(@Nullable Method readMethod) {
this.readMethod = readMethod;
}

Expand All @@ -303,7 +303,7 @@ public Method getWriteMethod() {
}

@Override
public void setWriteMethod(Method writeMethod) {
public void setWriteMethod(@Nullable Method writeMethod) {
this.writeMethod = writeMethod;
}

Expand All @@ -327,7 +327,7 @@ public Class<?> getPropertyEditorClass() {
}

@Override
public void setPropertyEditorClass(Class<?> propertyEditorClass) {
public void setPropertyEditorClass(@Nullable Class<?> propertyEditorClass) {
this.propertyEditorClass = propertyEditorClass;
}

Expand Down Expand Up @@ -399,7 +399,7 @@ public Method getReadMethod() {
}

@Override
public void setReadMethod(Method readMethod) {
public void setReadMethod(@Nullable Method readMethod) {
this.readMethod = readMethod;
}

Expand All @@ -410,7 +410,7 @@ public Method getWriteMethod() {
}

@Override
public void setWriteMethod(Method writeMethod) {
public void setWriteMethod(@Nullable Method writeMethod) {
this.writeMethod = writeMethod;
}

Expand All @@ -434,7 +434,7 @@ public Method getIndexedReadMethod() {
}

@Override
public void setIndexedReadMethod(Method indexedReadMethod) throws IntrospectionException {
public void setIndexedReadMethod(@Nullable Method indexedReadMethod) throws IntrospectionException {
this.indexedReadMethod = indexedReadMethod;
}

Expand All @@ -445,7 +445,7 @@ public Method getIndexedWriteMethod() {
}

@Override
public void setIndexedWriteMethod(Method indexedWriteMethod) throws IntrospectionException {
public void setIndexedWriteMethod(@Nullable Method indexedWriteMethod) throws IntrospectionException {
this.indexedWriteMethod = indexedWriteMethod;
}

Expand All @@ -470,7 +470,7 @@ public Class<?> getPropertyEditorClass() {
}

@Override
public void setPropertyEditorClass(Class<?> propertyEditorClass) {
public void setPropertyEditorClass(@Nullable Class<?> propertyEditorClass) {
this.propertyEditorClass = propertyEditorClass;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void setBeanClassLoader(ClassLoader classLoader) {
}

@Override
public void setBeanFactory(BeanFactory beanFactory) {
public void setBeanFactory(@Nullable BeanFactory beanFactory) {
this.beanFactory = beanFactory;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -554,8 +554,8 @@ public synchronized boolean isConverted() {
* 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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -106,7 +106,7 @@ public Class<?> getTargetClass() {
* @see #setTargetClass
* @see #setTargetField
*/
public void setTargetObject(Object targetObject) {
public void setTargetObject(@Nullable Object targetObject) {
this.targetObject = targetObject;
}

Expand All @@ -125,7 +125,7 @@ public Object getTargetObject() {
* @see #setTargetClass
* @see #setTargetObject
*/
public void setTargetField(String targetField) {
public void setTargetField(@Nullable String targetField) {
this.targetField = StringUtils.trimAllWhitespace(targetField);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@ public Class<?> getTargetType() {
/**
* 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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public final BeanDefinitionRegistry getRegistry() {
* @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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ public boolean isAllowEagerClassLoading() {
* @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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public Object getSource() {
/**
* 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;
}

Expand All @@ -86,7 +86,7 @@ public String getKeyTypeName() {
/**
* 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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public Object getSource() {
/**
* 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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ public void setParentName(@Nullable String parentName) {
/**
* 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;
}

Expand All @@ -276,7 +276,7 @@ public BeanDefinitionHolder getDecoratedDefinition() {
* @see #setTargetType(ResolvableType)
* @see #getResolvedFactoryMethod()
*/
public void setQualifiedElement(AnnotatedElement qualifiedElement) {
public void setQualifiedElement(@Nullable AnnotatedElement qualifiedElement) {
this.qualifiedElement = qualifiedElement;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
*/
public class EhCacheCacheManager extends AbstractTransactionSupportingCacheManager {

@Nullable
private net.sf.ehcache.CacheManager cacheManager;


Expand All @@ -59,7 +60,7 @@ public EhCacheCacheManager(net.sf.ehcache.CacheManager cacheManager) {
/**
* Set the backing EhCache {@link net.sf.ehcache.CacheManager}.
*/
public void setCacheManager(net.sf.ehcache.CacheManager cacheManager) {
public void setCacheManager(@Nullable net.sf.ehcache.CacheManager cacheManager) {
this.cacheManager = cacheManager;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
*/
public class JCacheCacheManager extends AbstractTransactionSupportingCacheManager {

@Nullable
private javax.cache.CacheManager cacheManager;

private boolean allowNullValues = true;
Expand All @@ -62,7 +63,7 @@ public JCacheCacheManager(CacheManager cacheManager) {
/**
* Set the backing JCache {@link javax.cache.CacheManager}.
*/
public void setCacheManager(javax.cache.CacheManager cacheManager) {
public void setCacheManager(@Nullable javax.cache.CacheManager cacheManager) {
this.cacheManager = cacheManager;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public class DefaultJCacheOperationSource extends AnnotationJCacheOperationSourc
* Set the default {@link CacheManager} to use to lookup cache by name. Only mandatory
* if the {@linkplain CacheResolver cache resolvers} have not been set.
*/
public void setCacheManager(CacheManager cacheManager) {
public void setCacheManager(@Nullable CacheManager cacheManager) {
this.cacheManager = cacheManager;
}

Expand All @@ -79,7 +79,7 @@ public CacheManager getCacheManager() {
* Set the {@link CacheResolver} to resolve regular caches. If none is set, a default
* implementation using the specified cache manager will be used.
*/
public void setCacheResolver(CacheResolver cacheResolver) {
public void setCacheResolver(@Nullable CacheResolver cacheResolver) {
this.cacheResolver = cacheResolver;
}

Expand All @@ -95,7 +95,7 @@ public CacheResolver getCacheResolver() {
* Set the {@link CacheResolver} to resolve exception caches. If none is set, a default
* implementation using the specified cache manager will be used.
*/
public void setExceptionCacheResolver(CacheResolver exceptionCacheResolver) {
public void setExceptionCacheResolver(@Nullable CacheResolver exceptionCacheResolver) {
this.exceptionCacheResolver = exceptionCacheResolver;
}

Expand All @@ -112,7 +112,7 @@ public CacheResolver getExceptionCacheResolver() {
* honoring the JSR-107 {@link javax.cache.annotation.CacheKey} and
* {@link javax.cache.annotation.CacheValue} will be used.
*/
public void setKeyGenerator(KeyGenerator keyGenerator) {
public void setKeyGenerator(@Nullable KeyGenerator keyGenerator) {
this.keyGenerator = keyGenerator;
}

Expand Down
Loading

0 comments on commit fb4ddb0

Please sign in to comment.