Skip to content

Commit fb4ddb0

Browse files
committed
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
1 parent ff85726 commit fb4ddb0

File tree

201 files changed

+579
-489
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

201 files changed

+579
-489
lines changed

spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJExpressionPointcutAdvisor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class AspectJExpressionPointcutAdvisor extends AbstractGenericPointcutAdv
3434
private final AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
3535

3636

37-
public void setExpression(String expression) {
37+
public void setExpression(@Nullable String expression) {
3838
this.pointcut.setExpression(expression);
3939
}
4040

@@ -43,7 +43,7 @@ public String getExpression() {
4343
return this.pointcut.getExpression();
4444
}
4545

46-
public void setLocation(String location) {
46+
public void setLocation(@Nullable String location) {
4747
this.pointcut.setLocation(location);
4848
}
4949

spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AbstractAutoProxyCreator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ public void setApplyCommonInterceptorsFirst(boolean applyCommonInterceptorsFirst
203203
}
204204

205205
@Override
206-
public void setBeanFactory(BeanFactory beanFactory) {
206+
public void setBeanFactory(@Nullable BeanFactory beanFactory) {
207207
this.beanFactory = beanFactory;
208208
}
209209

spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/DefaultAdvisorAutoProxyCreator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public boolean isUsePrefix() {
7070
* references. Default value is the bean name of this object + a dot.
7171
* @param advisorBeanNamePrefix the exclusion prefix
7272
*/
73-
public void setAdvisorBeanNamePrefix(String advisorBeanNamePrefix) {
73+
public void setAdvisorBeanNamePrefix(@Nullable String advisorBeanNamePrefix) {
7474
this.advisorBeanNamePrefix = advisorBeanNamePrefix;
7575
}
7676

spring-aop/src/main/java/org/springframework/aop/support/AbstractBeanFactoryPointcutAdvisor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public abstract class AbstractBeanFactoryPointcutAdvisor extends AbstractPointcu
6363
* of the advisor.
6464
* @see #getAdvice()
6565
*/
66-
public void setAdviceBeanName(String adviceBeanName) {
66+
public void setAdviceBeanName(@Nullable String adviceBeanName) {
6767
this.adviceBeanName = adviceBeanName;
6868
}
6969

spring-aop/src/main/java/org/springframework/aop/support/AbstractExpressionPointcut.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public abstract class AbstractExpressionPointcut implements ExpressionPointcut,
4343
/**
4444
* Set the location for debugging.
4545
*/
46-
public void setLocation(String location) {
46+
public void setLocation(@Nullable String location) {
4747
this.location = location;
4848
}
4949

@@ -58,7 +58,7 @@ public String getLocation() {
5858
return this.location;
5959
}
6060

61-
public void setExpression(String expression) {
61+
public void setExpression(@Nullable String expression) {
6262
this.expression = expression;
6363
try {
6464
onSetExpression(expression);
@@ -82,7 +82,7 @@ public void setExpression(String expression) {
8282
* @throws IllegalArgumentException if the expression is invalid
8383
* @see #setExpression
8484
*/
85-
protected void onSetExpression(String expression) throws IllegalArgumentException {
85+
protected void onSetExpression(@Nullable String expression) throws IllegalArgumentException {
8686
}
8787

8888
/**

spring-beans/src/main/java/org/springframework/beans/ExtendedBeanInfo.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ public Method getReadMethod() {
292292
}
293293

294294
@Override
295-
public void setReadMethod(Method readMethod) {
295+
public void setReadMethod(@Nullable Method readMethod) {
296296
this.readMethod = readMethod;
297297
}
298298

@@ -303,7 +303,7 @@ public Method getWriteMethod() {
303303
}
304304

305305
@Override
306-
public void setWriteMethod(Method writeMethod) {
306+
public void setWriteMethod(@Nullable Method writeMethod) {
307307
this.writeMethod = writeMethod;
308308
}
309309

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

329329
@Override
330-
public void setPropertyEditorClass(Class<?> propertyEditorClass) {
330+
public void setPropertyEditorClass(@Nullable Class<?> propertyEditorClass) {
331331
this.propertyEditorClass = propertyEditorClass;
332332
}
333333

@@ -399,7 +399,7 @@ public Method getReadMethod() {
399399
}
400400

401401
@Override
402-
public void setReadMethod(Method readMethod) {
402+
public void setReadMethod(@Nullable Method readMethod) {
403403
this.readMethod = readMethod;
404404
}
405405

@@ -410,7 +410,7 @@ public Method getWriteMethod() {
410410
}
411411

412412
@Override
413-
public void setWriteMethod(Method writeMethod) {
413+
public void setWriteMethod(@Nullable Method writeMethod) {
414414
this.writeMethod = writeMethod;
415415
}
416416

@@ -434,7 +434,7 @@ public Method getIndexedReadMethod() {
434434
}
435435

436436
@Override
437-
public void setIndexedReadMethod(Method indexedReadMethod) throws IntrospectionException {
437+
public void setIndexedReadMethod(@Nullable Method indexedReadMethod) throws IntrospectionException {
438438
this.indexedReadMethod = indexedReadMethod;
439439
}
440440

@@ -445,7 +445,7 @@ public Method getIndexedWriteMethod() {
445445
}
446446

447447
@Override
448-
public void setIndexedWriteMethod(Method indexedWriteMethod) throws IntrospectionException {
448+
public void setIndexedWriteMethod(@Nullable Method indexedWriteMethod) throws IntrospectionException {
449449
this.indexedWriteMethod = indexedWriteMethod;
450450
}
451451

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

472472
@Override
473-
public void setPropertyEditorClass(Class<?> propertyEditorClass) {
473+
public void setPropertyEditorClass(@Nullable Class<?> propertyEditorClass) {
474474
this.propertyEditorClass = propertyEditorClass;
475475
}
476476

spring-beans/src/main/java/org/springframework/beans/factory/config/AbstractFactoryBean.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public void setBeanClassLoader(ClassLoader classLoader) {
101101
}
102102

103103
@Override
104-
public void setBeanFactory(BeanFactory beanFactory) {
104+
public void setBeanFactory(@Nullable BeanFactory beanFactory) {
105105
this.beanFactory = beanFactory;
106106
}
107107

spring-beans/src/main/java/org/springframework/beans/factory/config/BeanDefinition.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement {
148148
* Set the names of the beans that this bean depends on being initialized.
149149
* The bean factory will guarantee that these beans get initialized first.
150150
*/
151-
void setDependsOn(String... dependsOn);
151+
void setDependsOn(@Nullable String... dependsOn);
152152

153153
/**
154154
* Return the bean names that this bean depends on.

spring-beans/src/main/java/org/springframework/beans/factory/config/ConstructorArgumentValues.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -554,8 +554,8 @@ public synchronized boolean isConverted() {
554554
* Set the converted value of the constructor argument,
555555
* after processed type conversion.
556556
*/
557-
public synchronized void setConvertedValue(Object value) {
558-
this.converted = true;
557+
public synchronized void setConvertedValue(@Nullable Object value) {
558+
this.converted = (value != null);
559559
this.convertedValue = value;
560560
}
561561

spring-beans/src/main/java/org/springframework/beans/factory/config/FieldRetrievingFactoryBean.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public class FieldRetrievingFactoryBean
8787
* @see #setTargetObject
8888
* @see #setTargetField
8989
*/
90-
public void setTargetClass(Class<?> targetClass) {
90+
public void setTargetClass(@Nullable Class<?> targetClass) {
9191
this.targetClass = targetClass;
9292
}
9393

@@ -106,7 +106,7 @@ public Class<?> getTargetClass() {
106106
* @see #setTargetClass
107107
* @see #setTargetField
108108
*/
109-
public void setTargetObject(Object targetObject) {
109+
public void setTargetObject(@Nullable Object targetObject) {
110110
this.targetObject = targetObject;
111111
}
112112

@@ -125,7 +125,7 @@ public Object getTargetObject() {
125125
* @see #setTargetClass
126126
* @see #setTargetObject
127127
*/
128-
public void setTargetField(String targetField) {
128+
public void setTargetField(@Nullable String targetField) {
129129
this.targetField = StringUtils.trimAllWhitespace(targetField);
130130
}
131131

spring-beans/src/main/java/org/springframework/beans/factory/config/TypedStringValue.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,7 @@ public Class<?> getTargetType() {
126126
/**
127127
* Specify the type to convert to.
128128
*/
129-
public void setTargetTypeName(String targetTypeName) {
130-
Assert.notNull(targetTypeName, "'targetTypeName' must not be null");
129+
public void setTargetTypeName(@Nullable String targetTypeName) {
131130
this.targetType = targetTypeName;
132131
}
133132

spring-beans/src/main/java/org/springframework/beans/factory/serviceloader/AbstractServiceLoaderBasedFactoryBean.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public abstract class AbstractServiceLoaderBasedFactoryBean extends AbstractFact
4545
/**
4646
* Specify the desired service type (typically the service's public API).
4747
*/
48-
public void setServiceType(Class<?> serviceType) {
48+
public void setServiceType(@Nullable Class<?> serviceType) {
4949
this.serviceType = serviceType;
5050
}
5151

spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanDefinitionReader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public final BeanDefinitionRegistry getRegistry() {
122122
* @see org.springframework.core.io.support.ResourcePatternResolver
123123
* @see org.springframework.core.io.support.PathMatchingResourcePatternResolver
124124
*/
125-
public void setResourceLoader(ResourceLoader resourceLoader) {
125+
public void setResourceLoader(@Nullable ResourceLoader resourceLoader) {
126126
this.resourceLoader = resourceLoader;
127127
}
128128

spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ public boolean isAllowEagerClassLoading() {
268268
* @see org.springframework.core.OrderComparator
269269
* @see org.springframework.core.annotation.AnnotationAwareOrderComparator
270270
*/
271-
public void setDependencyComparator(Comparator<Object> dependencyComparator) {
271+
public void setDependencyComparator(@Nullable Comparator<Object> dependencyComparator) {
272272
this.dependencyComparator = dependencyComparator;
273273
}
274274

spring-beans/src/main/java/org/springframework/beans/factory/support/ManagedMap.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public Object getSource() {
7171
/**
7272
* Set the default key type name (class name) to be used for this map.
7373
*/
74-
public void setKeyTypeName(String keyTypeName) {
74+
public void setKeyTypeName(@Nullable String keyTypeName) {
7575
this.keyTypeName = keyTypeName;
7676
}
7777

@@ -86,7 +86,7 @@ public String getKeyTypeName() {
8686
/**
8787
* Set the default value type name (class name) to be used for this map.
8888
*/
89-
public void setValueTypeName(String valueTypeName) {
89+
public void setValueTypeName(@Nullable String valueTypeName) {
9090
this.valueTypeName = valueTypeName;
9191
}
9292

spring-beans/src/main/java/org/springframework/beans/factory/support/ManagedSet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public Object getSource() {
6868
/**
6969
* Set the default element type name (class name) to be used for this set.
7070
*/
71-
public void setElementTypeName(String elementTypeName) {
71+
public void setElementTypeName(@Nullable String elementTypeName) {
7272
this.elementTypeName = elementTypeName;
7373
}
7474

spring-beans/src/main/java/org/springframework/beans/factory/support/RootBeanDefinition.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ public void setParentName(@Nullable String parentName) {
257257
/**
258258
* Register a target definition that is being decorated by this bean definition.
259259
*/
260-
public void setDecoratedDefinition(BeanDefinitionHolder decoratedDefinition) {
260+
public void setDecoratedDefinition(@Nullable BeanDefinitionHolder decoratedDefinition) {
261261
this.decoratedDefinition = decoratedDefinition;
262262
}
263263

@@ -276,7 +276,7 @@ public BeanDefinitionHolder getDecoratedDefinition() {
276276
* @see #setTargetType(ResolvableType)
277277
* @see #getResolvedFactoryMethod()
278278
*/
279-
public void setQualifiedElement(AnnotatedElement qualifiedElement) {
279+
public void setQualifiedElement(@Nullable AnnotatedElement qualifiedElement) {
280280
this.qualifiedElement = qualifiedElement;
281281
}
282282

spring-beans/src/main/java/org/springframework/beans/support/ArgumentConvertingMethodInvoker.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ public class ArgumentConvertingMethodInvoker extends MethodInvoker {
5555
* @see org.springframework.beans.SimpleTypeConverter
5656
* @see org.springframework.beans.BeanWrapperImpl
5757
*/
58-
public void setTypeConverter(TypeConverter typeConverter) {
58+
public void setTypeConverter(@Nullable TypeConverter typeConverter) {
5959
this.typeConverter = typeConverter;
60-
this.useDefaultConverter = false;
60+
this.useDefaultConverter = (typeConverter == null);
6161
}
6262

6363
/**

spring-context-support/src/main/java/org/springframework/cache/ehcache/EhCacheCacheManager.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
*/
3838
public class EhCacheCacheManager extends AbstractTransactionSupportingCacheManager {
3939

40+
@Nullable
4041
private net.sf.ehcache.CacheManager cacheManager;
4142

4243

@@ -59,7 +60,7 @@ public EhCacheCacheManager(net.sf.ehcache.CacheManager cacheManager) {
5960
/**
6061
* Set the backing EhCache {@link net.sf.ehcache.CacheManager}.
6162
*/
62-
public void setCacheManager(net.sf.ehcache.CacheManager cacheManager) {
63+
public void setCacheManager(@Nullable net.sf.ehcache.CacheManager cacheManager) {
6364
this.cacheManager = cacheManager;
6465
}
6566

spring-context-support/src/main/java/org/springframework/cache/jcache/JCacheCacheManager.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
*/
3939
public class JCacheCacheManager extends AbstractTransactionSupportingCacheManager {
4040

41+
@Nullable
4142
private javax.cache.CacheManager cacheManager;
4243

4344
private boolean allowNullValues = true;
@@ -62,7 +63,7 @@ public JCacheCacheManager(CacheManager cacheManager) {
6263
/**
6364
* Set the backing JCache {@link javax.cache.CacheManager}.
6465
*/
65-
public void setCacheManager(javax.cache.CacheManager cacheManager) {
66+
public void setCacheManager(@Nullable javax.cache.CacheManager cacheManager) {
6667
this.cacheManager = cacheManager;
6768
}
6869

spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/DefaultJCacheOperationSource.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public class DefaultJCacheOperationSource extends AnnotationJCacheOperationSourc
6363
* Set the default {@link CacheManager} to use to lookup cache by name. Only mandatory
6464
* if the {@linkplain CacheResolver cache resolvers} have not been set.
6565
*/
66-
public void setCacheManager(CacheManager cacheManager) {
66+
public void setCacheManager(@Nullable CacheManager cacheManager) {
6767
this.cacheManager = cacheManager;
6868
}
6969

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

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

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

0 commit comments

Comments
 (0)