This commit introduces 2 new @Nullable and @NonNullApi
annotations that leverage JSR 305 (dormant but available via
Findbugs jsr305 dependency and already used by libraries
like OkHttp) meta-annotations to specify explicitly
null-safety of Spring Framework parameters and return values.
In order to avoid adding too much annotations, the
default is set at package level with @NonNullApi and
@Nullable annotations are added when needed at parameter or
return value level. These annotations are intended to be used
on Spring Framework itself but also by other Spring projects.
@Nullable annotations have been introduced based on Javadoc
and search of patterns like "return null;". It is expected that
nullability of Spring Framework API will be polished with
complementary commits.
In practice, this will make the whole Spring Framework API
null-safe for Kotlin projects (when KT-10942 will be fixed)
since Kotlin will be able to leverage these annotations to
know if a parameter or a return value is nullable or not. But
this is also useful for Java developers as well since IntelliJ
IDEA, for example, also understands these annotations to
generate warnings when unsafe nullable usages are detected.
Issue: SPR-15540
@ -473,6 +474,7 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov
@@ -473,6 +474,7 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov
@ -75,7 +76,7 @@ public class AspectJAfterReturningAdvice extends AbstractAspectJAdvice
@@ -75,7 +76,7 @@ public class AspectJAfterReturningAdvice extends AbstractAspectJAdvice
// If we aren't dealing with a raw type, check if generic parameters are assignable.
@ -94,7 +95,7 @@ public class AspectJAfterReturningAdvice extends AbstractAspectJAdvice
@@ -94,7 +95,7 @@ public class AspectJAfterReturningAdvice extends AbstractAspectJAdvice
@ -382,6 +383,7 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
@@ -382,6 +383,7 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
@ -109,6 +110,7 @@ public class MethodInvocationProceedingJoinPoint implements ProceedingJoinPoint,
@@ -109,6 +110,7 @@ public class MethodInvocationProceedingJoinPoint implements ProceedingJoinPoint,
@ -125,6 +126,7 @@ public abstract class AbstractAspectJAdvisorFactory implements AspectJAdvisorFac
@@ -125,6 +126,7 @@ public abstract class AbstractAspectJAdvisorFactory implements AspectJAdvisorFac
@ -137,6 +139,7 @@ public abstract class AbstractAspectJAdvisorFactory implements AspectJAdvisorFac
@@ -137,6 +139,7 @@ public abstract class AbstractAspectJAdvisorFactory implements AspectJAdvisorFac
@ -113,7 +114,7 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto
@@ -113,7 +114,7 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto
@ -176,6 +177,7 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto
@@ -176,6 +177,7 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto
@ -208,6 +210,7 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto
@@ -208,6 +210,7 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto
@ -207,6 +208,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport
@@ -207,6 +208,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport
@ -400,6 +402,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport
@@ -400,6 +402,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport
// We can't create fancy target sources for directly registered singletons.
if(this.customTargetSourceCreators!=null&&
@ -578,7 +581,8 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport
@@ -578,7 +581,8 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport
@ -196,6 +197,7 @@ public abstract class AbstractBeanFactoryBasedTargetSourceCreator
@@ -196,6 +197,7 @@ public abstract class AbstractBeanFactoryBasedTargetSourceCreator
@ -317,7 +318,7 @@ public class CustomizableTraceInterceptor extends AbstractTraceInterceptor {
@@ -317,7 +318,7 @@ public class CustomizableTraceInterceptor extends AbstractTraceInterceptor {
@ -371,7 +372,7 @@ public class CustomizableTraceInterceptor extends AbstractTraceInterceptor {
@@ -371,7 +372,7 @@ public class CustomizableTraceInterceptor extends AbstractTraceInterceptor {
@ -66,6 +67,7 @@ public abstract class AbstractBeanFactoryPointcutAdvisor extends AbstractPointcu
@@ -66,6 +67,7 @@ public abstract class AbstractBeanFactoryPointcutAdvisor extends AbstractPointcu
@ -49,6 +51,7 @@ public abstract class AbstractExpressionPointcut implements ExpressionPointcut,
@@ -49,6 +51,7 @@ public abstract class AbstractExpressionPointcut implements ExpressionPointcut,
@ -64,7 +65,7 @@ public class DefaultIntroductionAdvisor implements IntroductionAdvisor, ClassFil
@@ -64,7 +65,7 @@ public class DefaultIntroductionAdvisor implements IntroductionAdvisor, ClassFil
@ -132,6 +133,7 @@ public class RegexpMethodPointcutAdvisor extends AbstractGenericPointcutAdvisor
@@ -132,6 +133,7 @@ public class RegexpMethodPointcutAdvisor extends AbstractGenericPointcutAdvisor
@ -69,7 +70,7 @@ public class AnnotationMatchingPointcut implements Pointcut {
@@ -69,7 +70,7 @@ public class AnnotationMatchingPointcut implements Pointcut {
@ -715,6 +716,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
@@ -715,6 +716,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
@ -727,6 +729,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
@@ -727,6 +729,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
@ -1016,6 +1019,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
@@ -1016,6 +1019,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
@ -98,6 +100,7 @@ public class BeanInstantiationException extends FatalBeanException {
@@ -98,6 +100,7 @@ public class BeanInstantiationException extends FatalBeanException {
*factorymethodorincaseofdefaultinstantiation
*@since4.3
*/
@Nullable
publicConstructor<?>getConstructor(){
returnthis.constructor;
}
@ -108,6 +111,7 @@ public class BeanInstantiationException extends FatalBeanException {
@@ -108,6 +111,7 @@ public class BeanInstantiationException extends FatalBeanException {
@ -60,6 +61,7 @@ public class BeanMetadataAttributeAccessor extends AttributeAccessorSupport impl
@@ -60,6 +61,7 @@ public class BeanMetadataAttributeAccessor extends AttributeAccessorSupport impl
@ -35,7 +37,7 @@ public class ConversionNotSupportedException extends TypeMismatchException {
@@ -35,7 +37,7 @@ public class ConversionNotSupportedException extends TypeMismatchException {
@ -45,7 +47,7 @@ public class ConversionNotSupportedException extends TypeMismatchException {
@@ -45,7 +47,7 @@ public class ConversionNotSupportedException extends TypeMismatchException {
@ -80,6 +82,7 @@ public class NotWritablePropertyException extends InvalidPropertyException {
@@ -80,6 +82,7 @@ public class NotWritablePropertyException extends InvalidPropertyException {
@ -71,6 +72,7 @@ public class PropertyBatchUpdateException extends BeansException {
@@ -71,6 +72,7 @@ public class PropertyBatchUpdateException extends BeansException {
@ -118,6 +119,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
@@ -118,6 +119,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
/**
*ReturntheassociatedConversionService,ifany.
*/
@Nullable
publicConversionServicegetConversionService(){
returnthis.conversionService;
}
@ -169,6 +171,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
@@ -169,6 +171,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
@ -336,7 +339,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
@@ -336,7 +339,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
@ -361,6 +364,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
@@ -361,6 +364,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
@ -371,6 +375,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
@@ -371,6 +375,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
@ -384,6 +389,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
@@ -384,6 +389,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
@ -420,6 +426,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
@@ -420,6 +426,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
@ -445,7 +452,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
@@ -445,7 +452,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
@ -55,7 +56,7 @@ public class TypeMismatchException extends PropertyAccessException {
@@ -55,7 +56,7 @@ public class TypeMismatchException extends PropertyAccessException {
@ -73,7 +74,7 @@ public class TypeMismatchException extends PropertyAccessException {
@@ -73,7 +74,7 @@ public class TypeMismatchException extends PropertyAccessException {
@ -83,7 +84,7 @@ public class TypeMismatchException extends PropertyAccessException {
@@ -83,7 +84,7 @@ public class TypeMismatchException extends PropertyAccessException {
super("Failed to convert value of type '"+ClassUtils.getDescriptiveType(value)+"'"+
(requiredType!=null?" to required type '"+ClassUtils.getQualifiedName(requiredType)+"'":""),
cause);
@ -103,6 +104,7 @@ public class TypeMismatchException extends PropertyAccessException {
@@ -103,6 +104,7 @@ public class TypeMismatchException extends PropertyAccessException {
@ -109,6 +110,7 @@ public class BeanCreationException extends FatalBeanException {
@@ -109,6 +110,7 @@ public class BeanCreationException extends FatalBeanException {
/**
*Returnthenameofthebeanrequested,ifany.
*/
@Nullable
publicStringgetBeanName(){
returnthis.beanName;
}
@ -117,6 +119,7 @@ public class BeanCreationException extends FatalBeanException {
@@ -117,6 +119,7 @@ public class BeanCreationException extends FatalBeanException {
*Returnthedescriptionoftheresourcethatthebean
*definitioncamefrom,ifany.
*/
@Nullable
publicStringgetResourceDescription(){
returnthis.resourceDescription;
}
@ -138,6 +141,7 @@ public class BeanCreationException extends FatalBeanException {
@@ -138,6 +141,7 @@ public class BeanCreationException extends FatalBeanException {
@ -47,7 +48,7 @@ public class BeanDefinitionStoreException extends FatalBeanException {
@@ -47,7 +48,7 @@ public class BeanDefinitionStoreException extends FatalBeanException {
@ -67,7 +68,7 @@ public class BeanDefinitionStoreException extends FatalBeanException {
@@ -67,7 +68,7 @@ public class BeanDefinitionStoreException extends FatalBeanException {
@ -91,7 +92,7 @@ public class BeanDefinitionStoreException extends FatalBeanException {
@@ -91,7 +92,7 @@ public class BeanDefinitionStoreException extends FatalBeanException {
super("Invalid bean definition with name '"+beanName+"' defined in "+resourceDescription+": "+msg,cause);
this.resourceDescription=resourceDescription;
this.beanName=beanName;
@ -102,6 +103,7 @@ public class BeanDefinitionStoreException extends FatalBeanException {
@@ -102,6 +103,7 @@ public class BeanDefinitionStoreException extends FatalBeanException {
*Returnthedescriptionoftheresourcethatthebean
*definitioncamefrom,ifany.
*/
@Nullable
publicStringgetResourceDescription(){
returnthis.resourceDescription;
}
@ -109,6 +111,7 @@ public class BeanDefinitionStoreException extends FatalBeanException {
@@ -109,6 +111,7 @@ public class BeanDefinitionStoreException extends FatalBeanException {
@ -85,6 +86,7 @@ public class NoUniqueBeanDefinitionException extends NoSuchBeanDefinitionExcepti
@@ -85,6 +86,7 @@ public class NoUniqueBeanDefinitionException extends NoSuchBeanDefinitionExcepti
@ -468,6 +469,7 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
@@ -468,6 +469,7 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
@ -691,6 +693,7 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
@@ -691,6 +693,7 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
@ -341,6 +342,7 @@ public class QualifierAnnotationAutowireCandidateResolver extends GenericTypeAwa
@@ -341,6 +342,7 @@ public class QualifierAnnotationAutowireCandidateResolver extends GenericTypeAwa