diff --git a/build.gradle b/build.gradle index a997ee1705..010391093a 100644 --- a/build.gradle +++ b/build.gradle @@ -177,6 +177,7 @@ configure(allprojects) { project -> } dependencies { + provided("com.google.code.findbugs:jsr305:3.0.2") testCompile("junit:junit:${junitVersion}") { exclude group:'org.hamcrest', module:'hamcrest-core' } diff --git a/spring-aop/src/main/java/org/aopalliance/aop/AspectException.java b/spring-aop/src/main/java/org/aopalliance/aop/AspectException.java index c634d51a06..3dd556656e 100644 --- a/spring-aop/src/main/java/org/aopalliance/aop/AspectException.java +++ b/spring-aop/src/main/java/org/aopalliance/aop/AspectException.java @@ -16,6 +16,8 @@ package org.aopalliance.aop; +import org.springframework.lang.Nullable; + /** * Superclass for all AOP infrastructure exceptions. * Unchecked, as such exceptions are fatal and end user @@ -41,7 +43,7 @@ public class AspectException extends RuntimeException { * @param message the exception message * @param cause the root cause, if any */ - public AspectException(String message, Throwable cause) { + public AspectException(String message, @Nullable Throwable cause) { super(message, cause); } diff --git a/spring-aop/src/main/java/org/aopalliance/intercept/MethodInterceptor.java b/spring-aop/src/main/java/org/aopalliance/intercept/MethodInterceptor.java index 8239b0e63b..a0b2be2a4d 100644 --- a/spring-aop/src/main/java/org/aopalliance/intercept/MethodInterceptor.java +++ b/spring-aop/src/main/java/org/aopalliance/intercept/MethodInterceptor.java @@ -16,6 +16,8 @@ package org.aopalliance.intercept; +import org.springframework.lang.Nullable; + /** * Intercepts calls on an interface on its way to the target. These * are nested "on top" of the target. @@ -52,6 +54,7 @@ public interface MethodInterceptor extends Interceptor { * @throws Throwable if the interceptors or the target object * throws an exception */ + @Nullable Object invoke(MethodInvocation invocation) throws Throwable; } diff --git a/spring-aop/src/main/java/org/springframework/aop/AfterReturningAdvice.java b/spring-aop/src/main/java/org/springframework/aop/AfterReturningAdvice.java index 46362c2b13..271e826711 100644 --- a/spring-aop/src/main/java/org/springframework/aop/AfterReturningAdvice.java +++ b/spring-aop/src/main/java/org/springframework/aop/AfterReturningAdvice.java @@ -18,6 +18,8 @@ package org.springframework.aop; import java.lang.reflect.Method; +import org.springframework.lang.Nullable; + /** * After returning advice is invoked only on normal method return, not if an * exception is thrown. Such advice can see the return value, but cannot change it. @@ -39,6 +41,6 @@ public interface AfterReturningAdvice extends AfterAdvice { * allowed by the method signature. Otherwise the exception * will be wrapped as a runtime exception. */ - void afterReturning(Object returnValue, Method method, Object[] args, Object target) throws Throwable; + void afterReturning(@Nullable Object returnValue, Method method, Object[] args, @Nullable Object target) throws Throwable; } diff --git a/spring-aop/src/main/java/org/springframework/aop/IntroductionAwareMethodMatcher.java b/spring-aop/src/main/java/org/springframework/aop/IntroductionAwareMethodMatcher.java index ed228bfa20..eceac03ea2 100644 --- a/spring-aop/src/main/java/org/springframework/aop/IntroductionAwareMethodMatcher.java +++ b/spring-aop/src/main/java/org/springframework/aop/IntroductionAwareMethodMatcher.java @@ -18,6 +18,8 @@ package org.springframework.aop; import java.lang.reflect.Method; +import org.springframework.lang.Nullable; + /** * A specialized type of {@link MethodMatcher} that takes into account introductions * when matching methods. If there are no introductions on the target class, @@ -39,6 +41,6 @@ public interface IntroductionAwareMethodMatcher extends MethodMatcher { * asking is the subject on one or more introductions; {@code false} otherwise * @return whether or not this method matches statically */ - boolean matches(Method method, Class targetClass, boolean hasIntroductions); + boolean matches(Method method, @Nullable Class targetClass, boolean hasIntroductions); } diff --git a/spring-aop/src/main/java/org/springframework/aop/MethodBeforeAdvice.java b/spring-aop/src/main/java/org/springframework/aop/MethodBeforeAdvice.java index fb8b08e220..cb6f8da209 100644 --- a/spring-aop/src/main/java/org/springframework/aop/MethodBeforeAdvice.java +++ b/spring-aop/src/main/java/org/springframework/aop/MethodBeforeAdvice.java @@ -18,6 +18,8 @@ package org.springframework.aop; import java.lang.reflect.Method; +import org.springframework.lang.Nullable; + /** * Advice invoked before a method is invoked. Such advices cannot * prevent the method call proceeding, unless they throw a Throwable. @@ -39,6 +41,6 @@ public interface MethodBeforeAdvice extends BeforeAdvice { * allowed by the method signature. Otherwise the exception * will be wrapped as a runtime exception. */ - void before(Method method, Object[] args, Object target) throws Throwable; + void before(Method method, Object[] args, @Nullable Object target) throws Throwable; } diff --git a/spring-aop/src/main/java/org/springframework/aop/MethodMatcher.java b/spring-aop/src/main/java/org/springframework/aop/MethodMatcher.java index 7cba7648cf..7b863b0712 100644 --- a/spring-aop/src/main/java/org/springframework/aop/MethodMatcher.java +++ b/spring-aop/src/main/java/org/springframework/aop/MethodMatcher.java @@ -18,6 +18,8 @@ package org.springframework.aop; import java.lang.reflect.Method; +import org.springframework.lang.Nullable; + /** * Part of a {@link Pointcut}: Checks whether the target method is eligible for advice. * @@ -57,7 +59,7 @@ public interface MethodMatcher { * the candidate class must be taken to be the method's declaring class) * @return whether or not this method matches statically */ - boolean matches(Method method, Class targetClass); + boolean matches(Method method, @Nullable Class targetClass); /** * Is this MethodMatcher dynamic, that is, must a final call be made on the @@ -86,7 +88,7 @@ public interface MethodMatcher { * @return whether there's a runtime match * @see MethodMatcher#matches(Method, Class) */ - boolean matches(Method method, Class targetClass, Object... args); + boolean matches(Method method, @Nullable Class targetClass, Object... args); /** diff --git a/spring-aop/src/main/java/org/springframework/aop/ProxyMethodInvocation.java b/spring-aop/src/main/java/org/springframework/aop/ProxyMethodInvocation.java index bee8192567..4c8ebeec2f 100644 --- a/spring-aop/src/main/java/org/springframework/aop/ProxyMethodInvocation.java +++ b/spring-aop/src/main/java/org/springframework/aop/ProxyMethodInvocation.java @@ -18,6 +18,8 @@ package org.springframework.aop; import org.aopalliance.intercept.MethodInvocation; +import org.springframework.lang.Nullable; + /** * Extension of the AOP Alliance {@link org.aopalliance.intercept.MethodInvocation} * interface, allowing access to the proxy that the method invocation was made through. @@ -73,7 +75,7 @@ public interface ProxyMethodInvocation extends MethodInvocation { * @param key the name of the attribute * @param value the value of the attribute, or {@code null} to reset it */ - void setUserAttribute(String key, Object value); + void setUserAttribute(String key, @Nullable Object value); /** * Return the value of the specified user attribute. @@ -81,6 +83,7 @@ public interface ProxyMethodInvocation extends MethodInvocation { * @return the value of the attribute, or {@code null} if not set * @see #setUserAttribute */ + @Nullable Object getUserAttribute(String key); } diff --git a/spring-aop/src/main/java/org/springframework/aop/TargetClassAware.java b/spring-aop/src/main/java/org/springframework/aop/TargetClassAware.java index 924437466b..28853700f2 100644 --- a/spring-aop/src/main/java/org/springframework/aop/TargetClassAware.java +++ b/spring-aop/src/main/java/org/springframework/aop/TargetClassAware.java @@ -16,6 +16,8 @@ package org.springframework.aop; +import org.springframework.lang.Nullable; + /** * Minimal interface for exposing the target class behind a proxy. * @@ -34,6 +36,7 @@ public interface TargetClassAware { * (typically a proxy configuration or an actual proxy). * @return the target Class, or {@code null} if not known */ + @Nullable Class getTargetClass(); } diff --git a/spring-aop/src/main/java/org/springframework/aop/TargetSource.java b/spring-aop/src/main/java/org/springframework/aop/TargetSource.java index 8e5ccc1fa6..b46eb19717 100644 --- a/spring-aop/src/main/java/org/springframework/aop/TargetSource.java +++ b/spring-aop/src/main/java/org/springframework/aop/TargetSource.java @@ -16,6 +16,8 @@ package org.springframework.aop; +import org.springframework.lang.Nullable; + /** * A {@code TargetSource} is used to obtain the current "target" of * an AOP invocation, which will be invoked via reflection if no around @@ -58,6 +60,7 @@ public interface TargetSource extends TargetClassAware { * @return the target object, which contains the joinpoint * @throws Exception if the target object can't be resolved */ + @Nullable Object getTarget() throws Exception; /** diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/AbstractAspectJAdvice.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/AbstractAspectJAdvice.java index 7020a05124..6240294239 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/AbstractAspectJAdvice.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/AbstractAspectJAdvice.java @@ -42,6 +42,7 @@ import org.springframework.aop.support.MethodMatchers; import org.springframework.aop.support.StaticMethodMatcher; import org.springframework.core.DefaultParameterNameDiscoverer; import org.springframework.core.ParameterNameDiscoverer; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.CollectionUtils; @@ -548,7 +549,7 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence * @param ex the exception thrown by the method execution (may be null) * @return the empty array if there are no arguments */ - protected Object[] argBinding(JoinPoint jp, JoinPointMatch jpMatch, Object returnValue, Throwable ex) { + protected Object[] argBinding(JoinPoint jp, JoinPointMatch jpMatch, @Nullable Object returnValue, @Nullable Throwable ex) { calculateArgumentBindings(); // AMC start @@ -607,7 +608,7 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence * @return the invocation result * @throws Throwable in case of invocation failure */ - protected Object invokeAdviceMethod(JoinPointMatch jpMatch, Object returnValue, Throwable ex) throws Throwable { + protected Object invokeAdviceMethod(JoinPointMatch jpMatch, @Nullable Object returnValue, @Nullable Throwable ex) throws Throwable { return invokeAdviceMethodWithGivenArgs(argBinding(getJoinPoint(), jpMatch, returnValue, ex)); } diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJAdviceParameterNameDiscoverer.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJAdviceParameterNameDiscoverer.java index fbb8febba9..aba3617cd7 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJAdviceParameterNameDiscoverer.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJAdviceParameterNameDiscoverer.java @@ -30,6 +30,7 @@ import org.aspectj.weaver.tools.PointcutParser; import org.aspectj.weaver.tools.PointcutPrimitive; import org.springframework.core.ParameterNameDiscoverer; +import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; /** @@ -473,6 +474,7 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov /* * If the token starts meets Java identifier conventions, it's in. */ + @Nullable private String maybeExtractVariableName(String candidateToken) { if (candidateToken == null || candidateToken.equals("")) { return null; diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJAfterReturningAdvice.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJAfterReturningAdvice.java index 92f9cb4ad9..f3dbb60630 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJAfterReturningAdvice.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJAfterReturningAdvice.java @@ -22,6 +22,7 @@ import java.lang.reflect.Type; import org.springframework.aop.AfterAdvice; import org.springframework.aop.AfterReturningAdvice; +import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.util.TypeUtils; @@ -75,7 +76,7 @@ public class AspectJAfterReturningAdvice extends AbstractAspectJAdvice * @param returnValue the return value of the target method * @return whether to invoke the advice method for the given return value */ - private boolean shouldInvokeOnReturnValueOf(Method method, Object returnValue) { + private boolean shouldInvokeOnReturnValueOf(Method method, @Nullable Object returnValue) { Class type = getDiscoveredReturningType(); Type genericType = getDiscoveredReturningGenericType(); // If we aren't dealing with a raw type, check if generic parameters are assignable. @@ -94,7 +95,7 @@ public class AspectJAfterReturningAdvice extends AbstractAspectJAdvice * @param returnValue the return value of the target method * @return whether to invoke the advice method for the given return value and type */ - private boolean matchesReturnValue(Class type, Method method, Object returnValue) { + private boolean matchesReturnValue(Class type, Method method, @Nullable Object returnValue) { if (returnValue != null) { return ClassUtils.isAssignableValue(type, returnValue); } diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJAopUtils.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJAopUtils.java index 2155c81cd5..d14b25e629 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJAopUtils.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJAopUtils.java @@ -21,6 +21,7 @@ import org.aopalliance.aop.Advice; import org.springframework.aop.Advisor; import org.springframework.aop.AfterAdvice; import org.springframework.aop.BeforeAdvice; +import org.springframework.lang.Nullable; /** * Utility methods for dealing with AspectJ advisors. @@ -58,6 +59,7 @@ public abstract class AspectJAopUtils { * If neither the advisor nor the advice have precedence information, this method * will return {@code null}. */ + @Nullable public static AspectJPrecedenceInformation getAspectJPrecedenceInformationFor(Advisor anAdvisor) { if (anAdvisor instanceof AspectJPrecedenceInformation) { return (AspectJPrecedenceInformation) anAdvisor; diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJExpressionPointcut.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJExpressionPointcut.java index 5a805052d6..2e21602fc8 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJExpressionPointcut.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJExpressionPointcut.java @@ -56,6 +56,7 @@ import org.springframework.beans.factory.BeanFactoryUtils; import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.annotation.BeanFactoryAnnotationUtils; import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; @@ -382,6 +383,7 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut /** * Get a new pointcut expression based on a target class's loader rather than the default. */ + @Nullable private PointcutExpression getFallbackPointcutExpression(Class targetClass) { try { ClassLoader classLoader = targetClass.getClassLoader(); diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/MethodInvocationProceedingJoinPoint.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/MethodInvocationProceedingJoinPoint.java index d6e43ec1fd..941047bbfe 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/MethodInvocationProceedingJoinPoint.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/MethodInvocationProceedingJoinPoint.java @@ -29,6 +29,7 @@ import org.aspectj.runtime.internal.AroundClosure; import org.springframework.aop.ProxyMethodInvocation; import org.springframework.core.DefaultParameterNameDiscoverer; import org.springframework.core.ParameterNameDiscoverer; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -109,6 +110,7 @@ public class MethodInvocationProceedingJoinPoint implements ProceedingJoinPoint, * Returns the Spring AOP target. May be {@code null} if there is no target. */ @Override + @Nullable public Object getTarget() { return this.methodInvocation.getThis(); } diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AbstractAspectJAdvisorFactory.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AbstractAspectJAdvisorFactory.java index 853657891c..2f4b7d67bd 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AbstractAspectJAdvisorFactory.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AbstractAspectJAdvisorFactory.java @@ -41,6 +41,7 @@ import org.aspectj.lang.reflect.PerClauseKind; import org.springframework.aop.framework.AopConfigException; import org.springframework.core.ParameterNameDiscoverer; import org.springframework.core.annotation.AnnotationUtils; +import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; /** @@ -125,6 +126,7 @@ public abstract class AbstractAspectJAdvisorFactory implements AspectJAdvisorFac * (there should only be one anyway...) */ @SuppressWarnings("unchecked") + @Nullable protected static AspectJAnnotation findAspectJAnnotationOnMethod(Method method) { Class[] classesToLookFor = new Class[] { Before.class, Around.class, After.class, AfterReturning.class, AfterThrowing.class, Pointcut.class}; @@ -137,6 +139,7 @@ public abstract class AbstractAspectJAdvisorFactory implements AspectJAdvisorFac return null; } + @Nullable private static AspectJAnnotation findAnnotation(Method method, Class toLookFor) { A result = AnnotationUtils.findAnnotation(method, toLookFor); if (result != null) { diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AspectJAdvisorFactory.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AspectJAdvisorFactory.java index 7eba0606d5..fa37957a74 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AspectJAdvisorFactory.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AspectJAdvisorFactory.java @@ -24,6 +24,7 @@ import org.aopalliance.aop.Advice; import org.springframework.aop.Advisor; import org.springframework.aop.aspectj.AspectJExpressionPointcut; import org.springframework.aop.framework.AopConfigException; +import org.springframework.lang.Nullable; /** * Interface for factories that can create Spring AOP Advisors from classes @@ -79,6 +80,7 @@ public interface AspectJAdvisorFactory { * or if it is a pointcut that will be used by other advice but will not * create a Spring advice in its own right */ + @Nullable Advisor getAdvisor(Method candidateAdviceMethod, MetadataAwareAspectInstanceFactory aspectInstanceFactory, int declarationOrder, String aspectName); @@ -98,6 +100,7 @@ public interface AspectJAdvisorFactory { * @see org.springframework.aop.aspectj.AspectJAfterReturningAdvice * @see org.springframework.aop.aspectj.AspectJAfterThrowingAdvice */ + @Nullable Advice getAdvice(Method candidateAdviceMethod, AspectJExpressionPointcut expressionPointcut, MetadataAwareAspectInstanceFactory aspectInstanceFactory, int declarationOrder, String aspectName); diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/MetadataAwareAspectInstanceFactory.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/MetadataAwareAspectInstanceFactory.java index 5f89f007c1..edf16993aa 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/MetadataAwareAspectInstanceFactory.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/MetadataAwareAspectInstanceFactory.java @@ -17,6 +17,7 @@ package org.springframework.aop.aspectj.annotation; import org.springframework.aop.aspectj.AspectInstanceFactory; +import org.springframework.lang.Nullable; /** * Subinterface of {@link org.springframework.aop.aspectj.AspectInstanceFactory} @@ -44,6 +45,7 @@ public interface MetadataAwareAspectInstanceFactory extends AspectInstanceFactor * @return the mutex object (may be {@code null} for no mutex to use) * @since 4.3 */ + @Nullable Object getAspectCreationMutex(); } diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/ReflectiveAspectJAdvisorFactory.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/ReflectiveAspectJAdvisorFactory.java index 010b8eec8b..c386a411c6 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/ReflectiveAspectJAdvisorFactory.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/ReflectiveAspectJAdvisorFactory.java @@ -50,6 +50,7 @@ import org.springframework.beans.factory.BeanFactory; import org.springframework.core.annotation.AnnotationUtils; import org.springframework.core.convert.converter.Converter; import org.springframework.core.convert.converter.ConvertingComparator; +import org.springframework.lang.Nullable; import org.springframework.util.ReflectionUtils; import org.springframework.util.StringUtils; import org.springframework.util.comparator.InstanceComparator; @@ -113,7 +114,7 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto * @see AspectJExpressionPointcut#setBeanFactory * @see org.springframework.beans.factory.config.ConfigurableBeanFactory#getBeanClassLoader() */ - public ReflectiveAspectJAdvisorFactory(BeanFactory beanFactory) { + public ReflectiveAspectJAdvisorFactory(@Nullable BeanFactory beanFactory) { this.beanFactory = beanFactory; } @@ -176,6 +177,7 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto * @param introductionField the field to introspect * @return {@code null} if not an Advisor */ + @Nullable private Advisor getDeclareParentsAdvisor(Field introductionField) { DeclareParents declareParents = introductionField.getAnnotation(DeclareParents.class); if (declareParents == null) { @@ -208,6 +210,7 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto this, aspectInstanceFactory, declarationOrderInAspect, aspectName); } + @Nullable private AspectJExpressionPointcut getPointcut(Method candidateAdviceMethod, Class candidateAspectClass) { AspectJAnnotation aspectJAnnotation = AbstractAspectJAdvisorFactory.findAspectJAnnotationOnMethod(candidateAdviceMethod); diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/package-info.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/package-info.java index 3c5ed99325..3a745025f0 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/package-info.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/package-info.java @@ -3,4 +3,7 @@ * *

Normally to be used through an AspectJAutoProxyCreator rather than directly. */ +@NonNullApi package org.springframework.aop.aspectj.annotation; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/autoproxy/package-info.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/autoproxy/package-info.java index 4ac96700ca..b9bb0d36f9 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/autoproxy/package-info.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/autoproxy/package-info.java @@ -2,4 +2,7 @@ * Base classes enabling auto-proxying based on AspectJ. * Support for AspectJ annotation aspects resides in the "aspectj.annotation" package. */ +@NonNullApi package org.springframework.aop.aspectj.autoproxy; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/package-info.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/package-info.java index d6415a15a3..3dcadb4e88 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/package-info.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/package-info.java @@ -8,4 +8,7 @@ * or AspectJ load-time weaver. It is intended to enable the use of a valuable subset of AspectJ * functionality, with consistent semantics, with the proxy-based Spring AOP framework. */ +@NonNullApi package org.springframework.aop.aspectj; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-aop/src/main/java/org/springframework/aop/config/AopConfigUtils.java b/spring-aop/src/main/java/org/springframework/aop/config/AopConfigUtils.java index 2088ada2b4..40ce417d83 100644 --- a/spring-aop/src/main/java/org/springframework/aop/config/AopConfigUtils.java +++ b/spring-aop/src/main/java/org/springframework/aop/config/AopConfigUtils.java @@ -26,6 +26,7 @@ import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.core.Ordered; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -104,7 +105,7 @@ public abstract class AopConfigUtils { } } - + @Nullable private static BeanDefinition registerOrEscalateApcAsRequired(Class cls, BeanDefinitionRegistry registry, Object source) { Assert.notNull(registry, "BeanDefinitionRegistry must not be null"); if (registry.containsBeanDefinition(AUTO_PROXY_CREATOR_BEAN_NAME)) { diff --git a/spring-aop/src/main/java/org/springframework/aop/config/ConfigBeanDefinitionParser.java b/spring-aop/src/main/java/org/springframework/aop/config/ConfigBeanDefinitionParser.java index b929d9f4a9..08c8a2591e 100644 --- a/spring-aop/src/main/java/org/springframework/aop/config/ConfigBeanDefinitionParser.java +++ b/spring-aop/src/main/java/org/springframework/aop/config/ConfigBeanDefinitionParser.java @@ -45,6 +45,7 @@ import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.beans.factory.xml.BeanDefinitionParser; import org.springframework.beans.factory.xml.ParserContext; +import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; import org.springframework.util.xml.DomUtils; @@ -466,6 +467,7 @@ class ConfigBeanDefinitionParser implements BeanDefinitionParser { * {@link org.springframework.beans.factory.config.BeanDefinition} for the pointcut if necessary * and returns its bean name, otherwise returns the bean name of the referred pointcut. */ + @Nullable private Object parsePointcutProperty(Element element, ParserContext parserContext) { if (element.hasAttribute(POINTCUT) && element.hasAttribute(POINTCUT_REF)) { parserContext.getReaderContext().error( diff --git a/spring-aop/src/main/java/org/springframework/aop/config/package-info.java b/spring-aop/src/main/java/org/springframework/aop/config/package-info.java index bb218b7e49..b5733f7f21 100644 --- a/spring-aop/src/main/java/org/springframework/aop/config/package-info.java +++ b/spring-aop/src/main/java/org/springframework/aop/config/package-info.java @@ -2,4 +2,7 @@ * Support package for declarative AOP configuration, * with XML schema being the primary configuration format. */ +@NonNullApi package org.springframework.aop.config; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/AdvisorChainFactory.java b/spring-aop/src/main/java/org/springframework/aop/framework/AdvisorChainFactory.java index a8774fa7be..87c0a810ee 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/AdvisorChainFactory.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/AdvisorChainFactory.java @@ -19,6 +19,8 @@ package org.springframework.aop.framework; import java.lang.reflect.Method; import java.util.List; +import org.springframework.lang.Nullable; + /** * Factory interface for advisor chains. * @@ -36,6 +38,6 @@ public interface AdvisorChainFactory { * target object, in which case the method's declaring class is the next best option) * @return List of MethodInterceptors (may also include InterceptorAndDynamicMethodMatchers) */ - List getInterceptorsAndDynamicInterceptionAdvice(Advised config, Method method, Class targetClass); + List getInterceptorsAndDynamicInterceptionAdvice(Advised config, Method method, @Nullable Class targetClass); } diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/AopContext.java b/spring-aop/src/main/java/org/springframework/aop/framework/AopContext.java index 06884dbd2f..d37f7a958d 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/AopContext.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/AopContext.java @@ -17,6 +17,7 @@ package org.springframework.aop.framework; import org.springframework.core.NamedThreadLocal; +import org.springframework.lang.Nullable; /** * Class containing static methods used to obtain information about the current AOP invocation. @@ -74,7 +75,8 @@ public abstract class AopContext { * @return the old proxy, which may be {@code null} if none was bound * @see #currentProxy() */ - static Object setCurrentProxy(Object proxy) { + @Nullable + static Object setCurrentProxy(@Nullable Object proxy) { Object old = currentProxy.get(); if (proxy != null) { currentProxy.set(proxy); diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/AopProxy.java b/spring-aop/src/main/java/org/springframework/aop/framework/AopProxy.java index 80c6690564..c25b4e61c7 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/AopProxy.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/AopProxy.java @@ -16,6 +16,8 @@ package org.springframework.aop.framework; +import org.springframework.lang.Nullable; + /** * Delegate interface for a configured AOP proxy, allowing for the creation * of actual proxy objects. @@ -48,6 +50,6 @@ public interface AopProxy { * (or {@code null} for the low-level proxy facility's default) * @return the new proxy object (never {@code null}) */ - Object getProxy(ClassLoader classLoader); + Object getProxy(@Nullable ClassLoader classLoader); } diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/AopProxyUtils.java b/spring-aop/src/main/java/org/springframework/aop/framework/AopProxyUtils.java index 7c611bad31..05c39b01d8 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/AopProxyUtils.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/AopProxyUtils.java @@ -27,6 +27,7 @@ import org.springframework.aop.TargetSource; import org.springframework.aop.support.AopUtils; import org.springframework.aop.target.SingletonTargetSource; import org.springframework.core.DecoratingProxy; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; @@ -52,6 +53,7 @@ public abstract class AopProxyUtils { * @see Advised#getTargetSource() * @see SingletonTargetSource#getTarget() */ + @Nullable public static Object getSingletonTarget(Object candidate) { if (candidate instanceof Advised) { TargetSource targetSource = ((Advised) candidate).getTargetSource(); diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/CglibAopProxy.java b/spring-aop/src/main/java/org/springframework/aop/framework/CglibAopProxy.java index 14cfcfb906..a21c64494b 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/CglibAopProxy.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/CglibAopProxy.java @@ -50,6 +50,7 @@ import org.springframework.cglib.proxy.MethodProxy; import org.springframework.cglib.proxy.NoOp; import org.springframework.cglib.transform.impl.UndeclaredThrowableStrategy; import org.springframework.core.SmartClassLoader; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.ObjectUtils; @@ -372,7 +373,8 @@ class CglibAopProxy implements AopProxy, Serializable { * Process a return value. Wraps a return of {@code this} if necessary to be the * {@code proxy} and also verifies that {@code null} is not returned as a primitive. */ - private static Object processReturnType(Object proxy, Object target, Method method, Object retVal) { + @Nullable + private static Object processReturnType(Object proxy, Object target, Method method, @Nullable Object retVal) { // Massage return value if necessary if (retVal != null && retVal == target && !RawTargetAccess.class.isAssignableFrom(method.getDeclaringClass())) { diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/ProxyFactory.java b/spring-aop/src/main/java/org/springframework/aop/framework/ProxyFactory.java index 854f9122f6..4da126ec44 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/ProxyFactory.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/ProxyFactory.java @@ -19,6 +19,7 @@ package org.springframework.aop.framework; import org.aopalliance.intercept.Interceptor; import org.springframework.aop.TargetSource; +import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; /** @@ -105,7 +106,7 @@ public class ProxyFactory extends ProxyCreatorSupport { * (or {@code null} for the low-level proxy facility's default) * @return the proxy object */ - public Object getProxy(ClassLoader classLoader) { + public Object getProxy(@Nullable ClassLoader classLoader) { return createAopProxy().getProxy(classLoader); } diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/adapter/package-info.java b/spring-aop/src/main/java/org/springframework/aop/framework/adapter/package-info.java index 8074a56ae3..a00663c252 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/adapter/package-info.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/adapter/package-info.java @@ -9,4 +9,7 @@ * *

These adapters do not depend on any other Spring framework classes to allow such usage. */ +@NonNullApi package org.springframework.aop.framework.adapter; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AbstractAutoProxyCreator.java b/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AbstractAutoProxyCreator.java index 18abf346ee..04400dd33b 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AbstractAutoProxyCreator.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AbstractAutoProxyCreator.java @@ -47,6 +47,7 @@ import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.config.SmartInstantiationAwareBeanPostProcessor; +import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; /** @@ -207,6 +208,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport * Return the owning {@link BeanFactory}. * May be {@code null}, as this post-processor doesn't need to belong to a bean factory. */ + @Nullable protected BeanFactory getBeanFactory() { return this.beanFactory; } @@ -400,6 +402,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport * @return a TargetSource for this bean * @see #setCustomTargetSourceCreators */ + @Nullable protected TargetSource getCustomTargetSource(Class beanClass, String beanName) { // 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 * @see #DO_NOT_PROXY * @see #PROXY_WITHOUT_ADDITIONAL_INTERCEPTORS */ + @Nullable protected abstract Object[] getAdvicesAndAdvisorsForBean( - Class beanClass, String beanName, TargetSource customTargetSource) throws BeansException; + Class beanClass, String beanName, @Nullable TargetSource customTargetSource) throws BeansException; } diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AutoProxyUtils.java b/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AutoProxyUtils.java index af39672c6c..21e135a3f6 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AutoProxyUtils.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AutoProxyUtils.java @@ -19,6 +19,7 @@ package org.springframework.aop.framework.autoproxy; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.core.Conventions; +import org.springframework.lang.Nullable; /** * Utilities for auto-proxy aware components. @@ -79,6 +80,7 @@ public abstract class AutoProxyUtils { * @since 4.2.3 * @see org.springframework.beans.factory.BeanFactory#getType(String) */ + @Nullable public static Class determineTargetClass(ConfigurableListableBeanFactory beanFactory, String beanName) { if (beanName == null) { return null; diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/ProxyCreationContext.java b/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/ProxyCreationContext.java index 0ba7a1ac45..cc7f6c3275 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/ProxyCreationContext.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/ProxyCreationContext.java @@ -17,6 +17,7 @@ package org.springframework.aop.framework.autoproxy; import org.springframework.core.NamedThreadLocal; +import org.springframework.lang.Nullable; /** * Holder for the current proxy creation context, as exposed by auto-proxy creators @@ -37,6 +38,7 @@ public class ProxyCreationContext { * Return the name of the currently proxied bean instance. * @return the name of the bean, or {@code null} if none available */ + @Nullable public static String getCurrentProxiedBeanName() { return currentProxiedBeanName.get(); } @@ -45,7 +47,7 @@ public class ProxyCreationContext { * Set the name of the currently proxied bean instance. * @param beanName the name of the bean, or {@code null} to reset it */ - static void setCurrentProxiedBeanName(String beanName) { + static void setCurrentProxiedBeanName(@Nullable String beanName) { if (beanName != null) { currentProxiedBeanName.set(beanName); } diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/TargetSourceCreator.java b/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/TargetSourceCreator.java index a962c3518b..d06933f550 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/TargetSourceCreator.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/TargetSourceCreator.java @@ -17,6 +17,7 @@ package org.springframework.aop.framework.autoproxy; import org.springframework.aop.TargetSource; +import org.springframework.lang.Nullable; /** * Implementations can create special target sources, such as pooling target @@ -39,6 +40,7 @@ public interface TargetSourceCreator { * @return a special TargetSource or {@code null} if this TargetSourceCreator isn't * interested in the particular bean */ + @Nullable TargetSource getTargetSource(Class beanClass, String beanName); } diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/package-info.java b/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/package-info.java index 376fc165ca..986c60f19d 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/package-info.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/package-info.java @@ -9,4 +9,7 @@ * as post-processors beans are only automatically detected in application contexts. * Post-processors can be explicitly registered on a ConfigurableBeanFactory instead. */ +@NonNullApi package org.springframework.aop.framework.autoproxy; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/target/AbstractBeanFactoryBasedTargetSourceCreator.java b/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/target/AbstractBeanFactoryBasedTargetSourceCreator.java index 48fd1c738c..09c2bff44d 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/target/AbstractBeanFactoryBasedTargetSourceCreator.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/target/AbstractBeanFactoryBasedTargetSourceCreator.java @@ -35,6 +35,7 @@ import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.beans.factory.support.GenericBeanDefinition; +import org.springframework.lang.Nullable; /** * Convenient superclass for @@ -196,6 +197,7 @@ public abstract class AbstractBeanFactoryBasedTargetSourceCreator * @param beanName the name of the bean * @return the AbstractPrototypeBasedTargetSource, or {@code null} if we don't match this */ + @Nullable protected abstract AbstractBeanFactoryBasedTargetSource createBeanFactoryBasedTargetSource( Class beanClass, String beanName); diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/target/package.html b/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/target/package.html deleted file mode 100644 index 264fe4aa56..0000000000 --- a/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/target/package.html +++ /dev/null @@ -1,7 +0,0 @@ - - - -Generic support classes for target source creation. - - - diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/package-info.java b/spring-aop/src/main/java/org/springframework/aop/framework/package-info.java index 31f8391c43..722fe85c55 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/package-info.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/package-info.java @@ -12,4 +12,7 @@ * or ApplicationContext. However, proxies can be created programmatically using the * ProxyFactory class. */ +@NonNullApi package org.springframework.aop.framework; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-aop/src/main/java/org/springframework/aop/interceptor/AsyncExecutionAspectSupport.java b/spring-aop/src/main/java/org/springframework/aop/interceptor/AsyncExecutionAspectSupport.java index f120147fe9..7ad3b28b1b 100644 --- a/spring-aop/src/main/java/org/springframework/aop/interceptor/AsyncExecutionAspectSupport.java +++ b/spring-aop/src/main/java/org/springframework/aop/interceptor/AsyncExecutionAspectSupport.java @@ -38,6 +38,7 @@ import org.springframework.core.task.AsyncListenableTaskExecutor; import org.springframework.core.task.AsyncTaskExecutor; import org.springframework.core.task.TaskExecutor; import org.springframework.core.task.support.TaskExecutorAdapter; +import org.springframework.lang.Nullable; import org.springframework.util.ReflectionUtils; import org.springframework.util.StringUtils; import org.springframework.util.concurrent.ListenableFuture; @@ -143,6 +144,7 @@ public abstract class AsyncExecutionAspectSupport implements BeanFactoryAware { * Should preferably return an {@link AsyncListenableTaskExecutor} implementation. * @return the executor to use (or {@code null}, but just if no default executor is available) */ + @Nullable protected AsyncTaskExecutor determineAsyncExecutor(Method method) { AsyncTaskExecutor executor = this.executors.get(method); if (executor == null) { @@ -183,6 +185,7 @@ public abstract class AsyncExecutionAspectSupport implements BeanFactoryAware { * @see #determineAsyncExecutor(Method) * @see #findQualifiedExecutor(BeanFactory, String) */ + @Nullable protected abstract String getExecutorQualifier(Method method); /** @@ -192,6 +195,7 @@ public abstract class AsyncExecutionAspectSupport implements BeanFactoryAware { * @since 4.2.6 * @see #getExecutorQualifier(Method) */ + @Nullable protected Executor findQualifiedExecutor(BeanFactory beanFactory, String qualifier) { if (beanFactory == null) { throw new IllegalStateException("BeanFactory must be set on " + getClass().getSimpleName() + @@ -212,6 +216,7 @@ public abstract class AsyncExecutionAspectSupport implements BeanFactoryAware { * @see #findQualifiedExecutor(BeanFactory, String) * @see #DEFAULT_TASK_EXECUTOR_BEAN_NAME */ + @Nullable protected Executor getDefaultExecutor(BeanFactory beanFactory) { if (beanFactory != null) { try { @@ -256,6 +261,7 @@ public abstract class AsyncExecutionAspectSupport implements BeanFactoryAware { * @param returnType the declared return type (potentially a {@link Future} variant) * @return the execution result (potentially a corresponding {@link Future} handle) */ + @Nullable protected Object doSubmit(Callable task, AsyncTaskExecutor executor, Class returnType) { if (CompletableFuture.class.isAssignableFrom(returnType)) { return CompletableFuture.supplyAsync(new Supplier() { diff --git a/spring-aop/src/main/java/org/springframework/aop/interceptor/CustomizableTraceInterceptor.java b/spring-aop/src/main/java/org/springframework/aop/interceptor/CustomizableTraceInterceptor.java index 4fbf04a0c2..c3e40f3540 100644 --- a/spring-aop/src/main/java/org/springframework/aop/interceptor/CustomizableTraceInterceptor.java +++ b/spring-aop/src/main/java/org/springframework/aop/interceptor/CustomizableTraceInterceptor.java @@ -24,6 +24,7 @@ import org.aopalliance.intercept.MethodInvocation; import org.apache.commons.logging.Log; import org.springframework.core.Constants; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.StopWatch; @@ -317,7 +318,7 @@ public class CustomizableTraceInterceptor extends AbstractTraceInterceptor { * @return the formatted output to write to the log */ protected String replacePlaceholders(String message, MethodInvocation methodInvocation, - Object returnValue, Throwable throwable, long invocationTime) { + @Nullable Object returnValue, @Nullable Throwable throwable, long invocationTime) { Matcher matcher = PATTERN.matcher(message); @@ -371,7 +372,7 @@ public class CustomizableTraceInterceptor extends AbstractTraceInterceptor { * @param returnValue the value returned by the method invocation. */ private void appendReturnValue( - MethodInvocation methodInvocation, Matcher matcher, StringBuffer output, Object returnValue) { + MethodInvocation methodInvocation, Matcher matcher, StringBuffer output, @Nullable Object returnValue) { if (methodInvocation.getMethod().getReturnType() == void.class) { matcher.appendReplacement(output, "void"); diff --git a/spring-aop/src/main/java/org/springframework/aop/interceptor/package-info.java b/spring-aop/src/main/java/org/springframework/aop/interceptor/package-info.java index dc57a3e965..7ec37824e5 100644 --- a/spring-aop/src/main/java/org/springframework/aop/interceptor/package-info.java +++ b/spring-aop/src/main/java/org/springframework/aop/interceptor/package-info.java @@ -3,4 +3,7 @@ * More specific interceptors can be found in corresponding * functionality packages, like "transaction" and "orm". */ +@NonNullApi package org.springframework.aop.interceptor; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-aop/src/main/java/org/springframework/aop/package-info.java b/spring-aop/src/main/java/org/springframework/aop/package-info.java index aaa6126598..7cdcbf66fc 100644 --- a/spring-aop/src/main/java/org/springframework/aop/package-info.java +++ b/spring-aop/src/main/java/org/springframework/aop/package-info.java @@ -17,4 +17,7 @@ *

Spring AOP can be used programmatically or (preferably) * integrated with the Spring IoC container. */ +@NonNullApi package org.springframework.aop; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-aop/src/main/java/org/springframework/aop/scope/package-info.java b/spring-aop/src/main/java/org/springframework/aop/scope/package-info.java index 5f4404db45..d48a870cf1 100644 --- a/spring-aop/src/main/java/org/springframework/aop/scope/package-info.java +++ b/spring-aop/src/main/java/org/springframework/aop/scope/package-info.java @@ -1,4 +1,7 @@ /** * Support for AOP-based scoping of target objects, with configurable backend. */ +@NonNullApi package org.springframework.aop.scope; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-aop/src/main/java/org/springframework/aop/support/AbstractBeanFactoryPointcutAdvisor.java b/spring-aop/src/main/java/org/springframework/aop/support/AbstractBeanFactoryPointcutAdvisor.java index 5401bb96a7..35f4e7362f 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/AbstractBeanFactoryPointcutAdvisor.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/AbstractBeanFactoryPointcutAdvisor.java @@ -24,6 +24,7 @@ import org.aopalliance.aop.Advice; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -66,6 +67,7 @@ public abstract class AbstractBeanFactoryPointcutAdvisor extends AbstractPointcu /** * Return the name of the advice bean that this advisor refers to, if any. */ + @Nullable public String getAdviceBeanName() { return this.adviceBeanName; } diff --git a/spring-aop/src/main/java/org/springframework/aop/support/AbstractExpressionPointcut.java b/spring-aop/src/main/java/org/springframework/aop/support/AbstractExpressionPointcut.java index 535b70a1e6..44c7604351 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/AbstractExpressionPointcut.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/AbstractExpressionPointcut.java @@ -18,6 +18,8 @@ package org.springframework.aop.support; import java.io.Serializable; +import org.springframework.lang.Nullable; + /** * Abstract superclass for expression pointcuts, * offering location and expression properties. @@ -49,6 +51,7 @@ public abstract class AbstractExpressionPointcut implements ExpressionPointcut, * @return location information as a human-readable String, * or {@code null} if none is available */ + @Nullable public String getLocation() { return this.location; } diff --git a/spring-aop/src/main/java/org/springframework/aop/support/AopUtils.java b/spring-aop/src/main/java/org/springframework/aop/support/AopUtils.java index 518901f3fa..69178a4ac0 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/AopUtils.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/AopUtils.java @@ -36,6 +36,7 @@ import org.springframework.aop.SpringProxy; import org.springframework.aop.TargetClassAware; import org.springframework.core.BridgeMethodResolver; import org.springframework.core.MethodIntrospector; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.ReflectionUtils; @@ -187,7 +188,7 @@ public abstract class AopUtils { * {@code targetClass} doesn't implement it or is {@code null} * @see org.springframework.util.ClassUtils#getMostSpecificMethod */ - public static Method getMostSpecificMethod(Method method, Class targetClass) { + public static Method getMostSpecificMethod(Method method, @Nullable Class targetClass) { Method resolvedMethod = ClassUtils.getMostSpecificMethod(method, targetClass); // If we are dealing with method with generic parameters, find the original method. return BridgeMethodResolver.findBridgedMethod(resolvedMethod); @@ -324,6 +325,7 @@ public abstract class AopUtils { * @throws Throwable if thrown by the target method * @throws org.springframework.aop.AopInvocationException in case of a reflection error */ + @Nullable public static Object invokeJoinpointUsingReflection(Object target, Method method, Object[] args) throws Throwable { diff --git a/spring-aop/src/main/java/org/springframework/aop/support/ControlFlowPointcut.java b/spring-aop/src/main/java/org/springframework/aop/support/ControlFlowPointcut.java index 47d201cfcd..1c339c0b66 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/ControlFlowPointcut.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/ControlFlowPointcut.java @@ -22,6 +22,7 @@ import java.lang.reflect.Method; import org.springframework.aop.ClassFilter; import org.springframework.aop.MethodMatcher; import org.springframework.aop.Pointcut; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; @@ -59,7 +60,7 @@ public class ControlFlowPointcut implements Pointcut, ClassFilter, MethodMatcher * @param clazz the clazz * @param methodName the name of the method (may be {@code null}) */ - public ControlFlowPointcut(Class clazz, String methodName) { + public ControlFlowPointcut(Class clazz, @Nullable String methodName) { Assert.notNull(clazz, "Class must not be null"); this.clazz = clazz; this.methodName = methodName; diff --git a/spring-aop/src/main/java/org/springframework/aop/support/DefaultIntroductionAdvisor.java b/spring-aop/src/main/java/org/springframework/aop/support/DefaultIntroductionAdvisor.java index bb192d4b5d..980bac49c1 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/DefaultIntroductionAdvisor.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/DefaultIntroductionAdvisor.java @@ -27,6 +27,7 @@ import org.springframework.aop.DynamicIntroductionAdvice; import org.springframework.aop.IntroductionAdvisor; import org.springframework.aop.IntroductionInfo; import org.springframework.core.Ordered; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; @@ -64,7 +65,7 @@ public class DefaultIntroductionAdvisor implements IntroductionAdvisor, ClassFil * @param introductionInfo the IntroductionInfo that describes * the interface to introduce (may be {@code null}) */ - public DefaultIntroductionAdvisor(Advice advice, IntroductionInfo introductionInfo) { + public DefaultIntroductionAdvisor(Advice advice, @Nullable IntroductionInfo introductionInfo) { Assert.notNull(advice, "Advice must not be null"); this.advice = advice; if (introductionInfo != null) { diff --git a/spring-aop/src/main/java/org/springframework/aop/support/MethodMatchers.java b/spring-aop/src/main/java/org/springframework/aop/support/MethodMatchers.java index 9a64d07431..9fac123ee8 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/MethodMatchers.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/MethodMatchers.java @@ -22,6 +22,7 @@ import java.lang.reflect.Method; import org.springframework.aop.ClassFilter; import org.springframework.aop.IntroductionAwareMethodMatcher; import org.springframework.aop.MethodMatcher; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -87,7 +88,7 @@ public abstract class MethodMatchers { * asking is the subject on one or more introductions; {@code false} otherwise * @return whether or not this method matches statically */ - public static boolean matches(MethodMatcher mm, Method method, Class targetClass, boolean hasIntroductions) { + public static boolean matches(MethodMatcher mm, Method method, @Nullable Class targetClass, boolean hasIntroductions) { Assert.notNull(mm, "MethodMatcher must not be null"); return ((mm instanceof IntroductionAwareMethodMatcher && ((IntroductionAwareMethodMatcher) mm).matches(method, targetClass, hasIntroductions)) || diff --git a/spring-aop/src/main/java/org/springframework/aop/support/RegexpMethodPointcutAdvisor.java b/spring-aop/src/main/java/org/springframework/aop/support/RegexpMethodPointcutAdvisor.java index 2d88b45c75..0fab429471 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/RegexpMethodPointcutAdvisor.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/RegexpMethodPointcutAdvisor.java @@ -21,6 +21,7 @@ import java.io.Serializable; import org.aopalliance.aop.Advice; import org.springframework.aop.Pointcut; +import org.springframework.lang.Nullable; import org.springframework.util.ObjectUtils; /** @@ -132,6 +133,7 @@ public class RegexpMethodPointcutAdvisor extends AbstractGenericPointcutAdvisor * will be used. * @return the Pointcut instance (never {@code null}) */ + @Nullable protected AbstractRegexpMethodPointcut createPointcut() { return new JdkRegexpMethodPointcut(); } diff --git a/spring-aop/src/main/java/org/springframework/aop/support/annotation/AnnotationMatchingPointcut.java b/spring-aop/src/main/java/org/springframework/aop/support/annotation/AnnotationMatchingPointcut.java index 68a77c8503..156e30e34f 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/annotation/AnnotationMatchingPointcut.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/annotation/AnnotationMatchingPointcut.java @@ -21,6 +21,7 @@ import java.lang.annotation.Annotation; import org.springframework.aop.ClassFilter; import org.springframework.aop.MethodMatcher; import org.springframework.aop.Pointcut; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; @@ -69,7 +70,7 @@ public class AnnotationMatchingPointcut implements Pointcut { * (can be {@code null}) */ public AnnotationMatchingPointcut( - Class classAnnotationType, Class methodAnnotationType) { + @Nullable Class classAnnotationType, @Nullable Class methodAnnotationType) { this(classAnnotationType, methodAnnotationType, false); } diff --git a/spring-aop/src/main/java/org/springframework/aop/support/annotation/package-info.java b/spring-aop/src/main/java/org/springframework/aop/support/annotation/package-info.java index a91142c972..0d65448e9c 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/annotation/package-info.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/annotation/package-info.java @@ -1,4 +1,7 @@ /** * Annotation support for AOP pointcuts. */ +@NonNullApi package org.springframework.aop.support.annotation; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-aop/src/main/java/org/springframework/aop/support/package-info.java b/spring-aop/src/main/java/org/springframework/aop/support/package-info.java index 88a441ed85..6e42276307 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/package-info.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/package-info.java @@ -1,4 +1,7 @@ /** * Convenience classes for using Spring's AOP API. */ +@NonNullApi package org.springframework.aop.support; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-aop/src/main/java/org/springframework/aop/target/EmptyTargetSource.java b/spring-aop/src/main/java/org/springframework/aop/target/EmptyTargetSource.java index 0e9ef50057..9f4936cb12 100644 --- a/spring-aop/src/main/java/org/springframework/aop/target/EmptyTargetSource.java +++ b/spring-aop/src/main/java/org/springframework/aop/target/EmptyTargetSource.java @@ -19,6 +19,7 @@ package org.springframework.aop.target; import java.io.Serializable; import org.springframework.aop.TargetSource; +import org.springframework.lang.Nullable; import org.springframework.util.ObjectUtils; /** @@ -50,7 +51,7 @@ public class EmptyTargetSource implements TargetSource, Serializable { * @param targetClass the target Class (may be {@code null}) * @see #getTargetClass() */ - public static EmptyTargetSource forClass(Class targetClass) { + public static EmptyTargetSource forClass(@Nullable Class targetClass) { return forClass(targetClass, true); } @@ -60,7 +61,7 @@ public class EmptyTargetSource implements TargetSource, Serializable { * @param isStatic whether the TargetSource should be marked as static * @see #getTargetClass() */ - public static EmptyTargetSource forClass(Class targetClass, boolean isStatic) { + public static EmptyTargetSource forClass(@Nullable Class targetClass, boolean isStatic) { return (targetClass == null && isStatic ? INSTANCE : new EmptyTargetSource(targetClass, isStatic)); } @@ -81,7 +82,7 @@ public class EmptyTargetSource implements TargetSource, Serializable { * @param targetClass the target class to expose (may be {@code null}) * @param isStatic whether the TargetSource is marked as static */ - private EmptyTargetSource(Class targetClass, boolean isStatic) { + private EmptyTargetSource(@Nullable Class targetClass, boolean isStatic) { this.targetClass = targetClass; this.isStatic = isStatic; } diff --git a/spring-aop/src/main/java/org/springframework/aop/target/dynamic/package.html b/spring-aop/src/main/java/org/springframework/aop/target/dynamic/package.html deleted file mode 100644 index bbbc9a55df..0000000000 --- a/spring-aop/src/main/java/org/springframework/aop/target/dynamic/package.html +++ /dev/null @@ -1,7 +0,0 @@ - - - -Support for AOP-based refreshing of target objects. - - - diff --git a/spring-beans/src/main/java/org/springframework/beans/AbstractNestablePropertyAccessor.java b/spring-beans/src/main/java/org/springframework/beans/AbstractNestablePropertyAccessor.java index ee869724a5..3275e59f9f 100644 --- a/spring-beans/src/main/java/org/springframework/beans/AbstractNestablePropertyAccessor.java +++ b/spring-beans/src/main/java/org/springframework/beans/AbstractNestablePropertyAccessor.java @@ -40,6 +40,7 @@ import org.springframework.core.ResolvableType; import org.springframework.core.convert.ConversionException; import org.springframework.core.convert.ConverterNotFoundException; import org.springframework.core.convert.TypeDescriptor; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; @@ -715,6 +716,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA * or {@code null} if not found * @throws BeansException in case of introspection failure */ + @Nullable protected PropertyHandler getPropertyHandler(String propertyName) throws BeansException { Assert.notNull(propertyName, "Property name must not be null"); AbstractNestablePropertyAccessor nestedPa = getPropertyAccessorForPropertyPath(propertyName); @@ -727,6 +729,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA * @param propertyName the name of a local property * @return the handler for that property or {@code null} if it has not been found */ + @Nullable protected abstract PropertyHandler getLocalPropertyHandler(String propertyName); /** @@ -1016,6 +1019,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA public abstract TypeDescriptor nested(int level); + @Nullable public abstract Object getValue() throws Exception; public abstract void setValue(Object object, Object value) throws Exception; diff --git a/spring-beans/src/main/java/org/springframework/beans/BeanInfoFactory.java b/spring-beans/src/main/java/org/springframework/beans/BeanInfoFactory.java index 4c5fd27cdc..52c73e4785 100644 --- a/spring-beans/src/main/java/org/springframework/beans/BeanInfoFactory.java +++ b/spring-beans/src/main/java/org/springframework/beans/BeanInfoFactory.java @@ -19,6 +19,8 @@ package org.springframework.beans; import java.beans.BeanInfo; import java.beans.IntrospectionException; +import org.springframework.lang.Nullable; + /** * Strategy interface for creating {@link BeanInfo} instances for Spring beans. * Can be used to plug in custom bean property resolution strategies (e.g. for other @@ -52,6 +54,7 @@ public interface BeanInfoFactory { * @return the BeanInfo, or {@code null} if the given class is not supported * @throws IntrospectionException in case of exceptions */ + @Nullable BeanInfo getBeanInfo(Class beanClass) throws IntrospectionException; } diff --git a/spring-beans/src/main/java/org/springframework/beans/BeanInstantiationException.java b/spring-beans/src/main/java/org/springframework/beans/BeanInstantiationException.java index d8f7d24609..976230f9df 100644 --- a/spring-beans/src/main/java/org/springframework/beans/BeanInstantiationException.java +++ b/spring-beans/src/main/java/org/springframework/beans/BeanInstantiationException.java @@ -19,6 +19,8 @@ package org.springframework.beans; import java.lang.reflect.Constructor; import java.lang.reflect.Method; +import org.springframework.lang.Nullable; + /** * Exception thrown when instantiation of a bean failed. * Carries the offending bean class. @@ -98,6 +100,7 @@ public class BeanInstantiationException extends FatalBeanException { * factory method or in case of default instantiation * @since 4.3 */ + @Nullable public Constructor getConstructor() { return this.constructor; } @@ -108,6 +111,7 @@ public class BeanInstantiationException extends FatalBeanException { * or {@code null} in case of constructor-based instantiation * @since 4.3 */ + @Nullable public Method getConstructingMethod() { return this.constructingMethod; } diff --git a/spring-beans/src/main/java/org/springframework/beans/BeanMetadataAttributeAccessor.java b/spring-beans/src/main/java/org/springframework/beans/BeanMetadataAttributeAccessor.java index d08a8fa341..9f75cfef3c 100644 --- a/spring-beans/src/main/java/org/springframework/beans/BeanMetadataAttributeAccessor.java +++ b/spring-beans/src/main/java/org/springframework/beans/BeanMetadataAttributeAccessor.java @@ -17,6 +17,7 @@ package org.springframework.beans; import org.springframework.core.AttributeAccessorSupport; +import org.springframework.lang.Nullable; /** * Extension of {@link org.springframework.core.AttributeAccessorSupport}, @@ -60,6 +61,7 @@ public class BeanMetadataAttributeAccessor extends AttributeAccessorSupport impl * @return the corresponding BeanMetadataAttribute object, * or {@code null} if no such attribute defined */ + @Nullable public BeanMetadataAttribute getMetadataAttribute(String name) { return (BeanMetadataAttribute) super.getAttribute(name); } diff --git a/spring-beans/src/main/java/org/springframework/beans/BeanMetadataElement.java b/spring-beans/src/main/java/org/springframework/beans/BeanMetadataElement.java index 6b6229d416..6fc10ba9ee 100644 --- a/spring-beans/src/main/java/org/springframework/beans/BeanMetadataElement.java +++ b/spring-beans/src/main/java/org/springframework/beans/BeanMetadataElement.java @@ -16,6 +16,8 @@ package org.springframework.beans; +import org.springframework.lang.Nullable; + /** * Interface to be implemented by bean metadata elements * that carry a configuration source object. @@ -29,6 +31,7 @@ public interface BeanMetadataElement { * Return the configuration source {@code Object} for this metadata element * (may be {@code null}). */ + @Nullable Object getSource(); } diff --git a/spring-beans/src/main/java/org/springframework/beans/BeanUtils.java b/spring-beans/src/main/java/org/springframework/beans/BeanUtils.java index aacf3e2b65..0a73d0893a 100644 --- a/spring-beans/src/main/java/org/springframework/beans/BeanUtils.java +++ b/spring-beans/src/main/java/org/springframework/beans/BeanUtils.java @@ -35,6 +35,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.core.MethodParameter; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.ConcurrentReferenceHashMap; @@ -172,6 +173,7 @@ public abstract class BeanUtils { * @see Class#getMethod * @see #findDeclaredMethod */ + @Nullable public static Method findMethod(Class clazz, String methodName, Class... paramTypes) { try { return clazz.getMethod(methodName, paramTypes); @@ -192,6 +194,7 @@ public abstract class BeanUtils { * @return the Method object, or {@code null} if not found * @see Class#getDeclaredMethod */ + @Nullable public static Method findDeclaredMethod(Class clazz, String methodName, Class... paramTypes) { try { return clazz.getDeclaredMethod(methodName, paramTypes); @@ -219,6 +222,7 @@ public abstract class BeanUtils { * @see Class#getMethods * @see #findDeclaredMethodWithMinimalParameters */ + @Nullable public static Method findMethodWithMinimalParameters(Class clazz, String methodName) throws IllegalArgumentException { @@ -241,6 +245,7 @@ public abstract class BeanUtils { * could not be resolved to a unique method with minimal parameters * @see Class#getDeclaredMethods */ + @Nullable public static Method findDeclaredMethodWithMinimalParameters(Class clazz, String methodName) throws IllegalArgumentException { @@ -260,6 +265,7 @@ public abstract class BeanUtils { * @throws IllegalArgumentException if methods of the given name were found but * could not be resolved to a unique method with minimal parameters */ + @Nullable public static Method findMethodWithMinimalParameters(Method[] methods, String methodName) throws IllegalArgumentException { @@ -311,6 +317,7 @@ public abstract class BeanUtils { * @see #findMethod * @see #findMethodWithMinimalParameters */ + @Nullable public static Method resolveSignature(String signature, Class clazz) { Assert.hasText(signature, "'signature' must not be empty"); Assert.notNull(clazz, "Class must not be null"); @@ -365,6 +372,7 @@ public abstract class BeanUtils { * @return the corresponding PropertyDescriptor, or {@code null} if none * @throws BeansException if PropertyDescriptor lookup fails */ + @Nullable public static PropertyDescriptor getPropertyDescriptor(Class clazz, String propertyName) throws BeansException { @@ -381,6 +389,7 @@ public abstract class BeanUtils { * @return the corresponding PropertyDescriptor, or {@code null} if none * @throws BeansException if PropertyDescriptor lookup fails */ + @Nullable public static PropertyDescriptor findPropertyForMethod(Method method) throws BeansException { return findPropertyForMethod(method, method.getDeclaringClass()); } @@ -395,6 +404,7 @@ public abstract class BeanUtils { * @throws BeansException if PropertyDescriptor lookup fails * @since 3.2.13 */ + @Nullable public static PropertyDescriptor findPropertyForMethod(Method method, Class clazz) throws BeansException { Assert.notNull(method, "Method must not be null"); PropertyDescriptor[] pds = getPropertyDescriptors(clazz); @@ -415,6 +425,7 @@ public abstract class BeanUtils { * @param targetType the type to find an editor for * @return the corresponding editor, or {@code null} if none found */ + @Nullable public static PropertyEditor findEditorByConvention(Class targetType) { if (targetType == null || targetType.isArray() || unknownEditorTypes.contains(targetType)) { return null; diff --git a/spring-beans/src/main/java/org/springframework/beans/BeanWrapper.java b/spring-beans/src/main/java/org/springframework/beans/BeanWrapper.java index 437a450c61..1aa32d3733 100644 --- a/spring-beans/src/main/java/org/springframework/beans/BeanWrapper.java +++ b/spring-beans/src/main/java/org/springframework/beans/BeanWrapper.java @@ -18,6 +18,8 @@ package org.springframework.beans; import java.beans.PropertyDescriptor; +import org.springframework.lang.Nullable; + /** * The central interface of Spring's low-level JavaBeans infrastructure. * @@ -65,6 +67,7 @@ public interface BeanWrapper extends ConfigurablePropertyAccessor { * Return the bean instance wrapped by this object, if any. * @return the bean instance, or {@code null} if none set */ + @Nullable Object getWrappedInstance(); /** @@ -72,6 +75,7 @@ public interface BeanWrapper extends ConfigurablePropertyAccessor { * @return the type of the wrapped bean instance, * or {@code null} if no wrapped object has been set */ + @Nullable Class getWrappedClass(); /** diff --git a/spring-beans/src/main/java/org/springframework/beans/ConfigurablePropertyAccessor.java b/spring-beans/src/main/java/org/springframework/beans/ConfigurablePropertyAccessor.java index efa3c58c31..77fb0ee6d2 100644 --- a/spring-beans/src/main/java/org/springframework/beans/ConfigurablePropertyAccessor.java +++ b/spring-beans/src/main/java/org/springframework/beans/ConfigurablePropertyAccessor.java @@ -17,6 +17,7 @@ package org.springframework.beans; import org.springframework.core.convert.ConversionService; +import org.springframework.lang.Nullable; /** * Interface that encapsulates configuration methods for a PropertyAccessor. @@ -41,6 +42,7 @@ public interface ConfigurablePropertyAccessor extends PropertyAccessor, Property /** * Return the associated ConversionService, if any. */ + @Nullable ConversionService getConversionService(); /** diff --git a/spring-beans/src/main/java/org/springframework/beans/ConversionNotSupportedException.java b/spring-beans/src/main/java/org/springframework/beans/ConversionNotSupportedException.java index 26a8db336b..3c17ec53d0 100644 --- a/spring-beans/src/main/java/org/springframework/beans/ConversionNotSupportedException.java +++ b/spring-beans/src/main/java/org/springframework/beans/ConversionNotSupportedException.java @@ -18,6 +18,8 @@ package org.springframework.beans; import java.beans.PropertyChangeEvent; +import org.springframework.lang.Nullable; + /** * Exception thrown when no suitable editor or converter can be found for a bean property. * @@ -35,7 +37,7 @@ public class ConversionNotSupportedException extends TypeMismatchException { * @param cause the root cause (may be {@code null}) */ public ConversionNotSupportedException(PropertyChangeEvent propertyChangeEvent, - Class requiredType, Throwable cause) { + @Nullable Class requiredType, @Nullable Throwable cause) { super(propertyChangeEvent, requiredType, cause); } @@ -45,7 +47,7 @@ public class ConversionNotSupportedException extends TypeMismatchException { * @param requiredType the required target type (or {@code null} if not known) * @param cause the root cause (may be {@code null}) */ - public ConversionNotSupportedException(Object value, Class requiredType, Throwable cause) { + public ConversionNotSupportedException(@Nullable Object value, @Nullable Class requiredType, @Nullable Throwable cause) { super(value, requiredType, cause); } diff --git a/spring-beans/src/main/java/org/springframework/beans/ExtendedBeanInfo.java b/spring-beans/src/main/java/org/springframework/beans/ExtendedBeanInfo.java index 3d1cfa5610..9bd39e28b1 100644 --- a/spring-beans/src/main/java/org/springframework/beans/ExtendedBeanInfo.java +++ b/spring-beans/src/main/java/org/springframework/beans/ExtendedBeanInfo.java @@ -37,6 +37,7 @@ import java.util.TreeSet; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.lang.Nullable; import org.springframework.util.ObjectUtils; /** @@ -188,6 +189,7 @@ class ExtendedBeanInfo implements BeanInfo { } } + @Nullable private PropertyDescriptor findExistingPropertyDescriptor(String propertyName, Class propertyType) { for (PropertyDescriptor pd : this.propertyDescriptors) { final Class candidateType; diff --git a/spring-beans/src/main/java/org/springframework/beans/Mergeable.java b/spring-beans/src/main/java/org/springframework/beans/Mergeable.java index cba64d94f8..cde059bb84 100644 --- a/spring-beans/src/main/java/org/springframework/beans/Mergeable.java +++ b/spring-beans/src/main/java/org/springframework/beans/Mergeable.java @@ -16,6 +16,8 @@ package org.springframework.beans; +import org.springframework.lang.Nullable; + /** * Interface representing an object whose value set can be merged with * that of a parent object. @@ -44,6 +46,6 @@ public interface Mergeable { * @exception IllegalStateException if merging is not enabled for this instance * (i.e. {@code mergeEnabled} equals {@code false}). */ - Object merge(Object parent); + Object merge(@Nullable Object parent); } diff --git a/spring-beans/src/main/java/org/springframework/beans/MutablePropertyValues.java b/spring-beans/src/main/java/org/springframework/beans/MutablePropertyValues.java index 43136433d8..8adc4e9d0b 100644 --- a/spring-beans/src/main/java/org/springframework/beans/MutablePropertyValues.java +++ b/spring-beans/src/main/java/org/springframework/beans/MutablePropertyValues.java @@ -23,6 +23,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; /** @@ -267,6 +268,7 @@ public class MutablePropertyValues implements PropertyValues, Serializable { * @see #getPropertyValue(String) * @see PropertyValue#getValue() */ + @Nullable public Object get(String propertyName) { PropertyValue pv = getPropertyValue(propertyName); return (pv != null ? pv.getValue() : null); diff --git a/spring-beans/src/main/java/org/springframework/beans/NotWritablePropertyException.java b/spring-beans/src/main/java/org/springframework/beans/NotWritablePropertyException.java index b1a05a14a1..cac0a15d90 100644 --- a/spring-beans/src/main/java/org/springframework/beans/NotWritablePropertyException.java +++ b/spring-beans/src/main/java/org/springframework/beans/NotWritablePropertyException.java @@ -16,6 +16,8 @@ package org.springframework.beans; +import org.springframework.lang.Nullable; + /** * Exception thrown on an attempt to set the value of a property that * is not writable (typically because there is no setter method). @@ -80,6 +82,7 @@ public class NotWritablePropertyException extends InvalidPropertyException { * Return suggestions for actual bean property names that closely match * the invalid property name, if any. */ + @Nullable public String[] getPossibleMatches() { return this.possibleMatches; } diff --git a/spring-beans/src/main/java/org/springframework/beans/PropertyAccessException.java b/spring-beans/src/main/java/org/springframework/beans/PropertyAccessException.java index 07cbb3d5bc..1bb6c4ff31 100644 --- a/spring-beans/src/main/java/org/springframework/beans/PropertyAccessException.java +++ b/spring-beans/src/main/java/org/springframework/beans/PropertyAccessException.java @@ -18,6 +18,8 @@ package org.springframework.beans; import java.beans.PropertyChangeEvent; +import org.springframework.lang.Nullable; + /** * Superclass for exceptions related to a property access, * such as type mismatch or invocation target exception. @@ -57,6 +59,7 @@ public abstract class PropertyAccessException extends BeansException { *

May be {@code null}; only available if an actual bean property * was affected. */ + @Nullable public PropertyChangeEvent getPropertyChangeEvent() { return this.propertyChangeEvent; } @@ -71,6 +74,7 @@ public abstract class PropertyAccessException extends BeansException { /** * Return the affected value that was about to be set, if any. */ + @Nullable public Object getValue() { return (this.propertyChangeEvent != null ? this.propertyChangeEvent.getNewValue() : null); } diff --git a/spring-beans/src/main/java/org/springframework/beans/PropertyAccessor.java b/spring-beans/src/main/java/org/springframework/beans/PropertyAccessor.java index c7faf35524..2693b7c781 100644 --- a/spring-beans/src/main/java/org/springframework/beans/PropertyAccessor.java +++ b/spring-beans/src/main/java/org/springframework/beans/PropertyAccessor.java @@ -19,6 +19,7 @@ package org.springframework.beans; import java.util.Map; import org.springframework.core.convert.TypeDescriptor; +import org.springframework.lang.Nullable; /** * Common interface for classes that can access named properties @@ -86,6 +87,7 @@ public interface PropertyAccessor { * @throws PropertyAccessException if the property was valid but the * accessor method failed */ + @Nullable Class getPropertyType(String propertyName) throws BeansException; /** @@ -98,6 +100,7 @@ public interface PropertyAccessor { * @throws InvalidPropertyException if there is no such property or * if the property isn't readable */ + @Nullable TypeDescriptor getPropertyTypeDescriptor(String propertyName) throws BeansException; /** diff --git a/spring-beans/src/main/java/org/springframework/beans/PropertyBatchUpdateException.java b/spring-beans/src/main/java/org/springframework/beans/PropertyBatchUpdateException.java index bfa54687bb..64b7ca3b8c 100644 --- a/spring-beans/src/main/java/org/springframework/beans/PropertyBatchUpdateException.java +++ b/spring-beans/src/main/java/org/springframework/beans/PropertyBatchUpdateException.java @@ -19,6 +19,7 @@ package org.springframework.beans; import java.io.PrintStream; import java.io.PrintWriter; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; @@ -71,6 +72,7 @@ public class PropertyBatchUpdateException extends BeansException { /** * Return the exception for this field, or {@code null} if there isn't any. */ + @Nullable public PropertyAccessException getPropertyAccessException(String propertyName) { for (PropertyAccessException pae : this.propertyAccessExceptions) { if (ObjectUtils.nullSafeEquals(propertyName, pae.getPropertyName())) { diff --git a/spring-beans/src/main/java/org/springframework/beans/PropertyEditorRegistry.java b/spring-beans/src/main/java/org/springframework/beans/PropertyEditorRegistry.java index f76df2a2d8..1bd83a254f 100644 --- a/spring-beans/src/main/java/org/springframework/beans/PropertyEditorRegistry.java +++ b/spring-beans/src/main/java/org/springframework/beans/PropertyEditorRegistry.java @@ -18,6 +18,8 @@ package org.springframework.beans; import java.beans.PropertyEditor; +import org.springframework.lang.Nullable; + /** * Encapsulates methods for registering JavaBeans {@link PropertyEditor PropertyEditors}. * This is the central interface that a {@link PropertyEditorRegistrar} operates on. @@ -64,7 +66,7 @@ public interface PropertyEditorRegistry { * {@code null} if registering an editor for all properties of the given type * @param propertyEditor editor to register */ - void registerCustomEditor(Class requiredType, String propertyPath, PropertyEditor propertyEditor); + void registerCustomEditor(@Nullable Class requiredType, @Nullable String propertyPath, PropertyEditor propertyEditor); /** * Find a custom property editor for the given type and property. @@ -74,6 +76,7 @@ public interface PropertyEditorRegistry { * {@code null} if looking for an editor for all properties of the given type * @return the registered editor, or {@code null} if none */ - PropertyEditor findCustomEditor(Class requiredType, String propertyPath); + @Nullable + PropertyEditor findCustomEditor(@Nullable Class requiredType, @Nullable String propertyPath); } diff --git a/spring-beans/src/main/java/org/springframework/beans/PropertyEditorRegistrySupport.java b/spring-beans/src/main/java/org/springframework/beans/PropertyEditorRegistrySupport.java index c28a2cf269..ef70b224f3 100644 --- a/spring-beans/src/main/java/org/springframework/beans/PropertyEditorRegistrySupport.java +++ b/spring-beans/src/main/java/org/springframework/beans/PropertyEditorRegistrySupport.java @@ -74,6 +74,7 @@ import org.springframework.beans.propertyeditors.ZoneIdEditor; import org.springframework.core.convert.ConversionService; import org.springframework.core.io.Resource; import org.springframework.core.io.support.ResourceArrayPropertyEditor; +import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; /** @@ -118,6 +119,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry { /** * Return the associated ConversionService, if any. */ + @Nullable public ConversionService getConversionService() { return this.conversionService; } @@ -169,6 +171,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry { * @return the default editor, or {@code null} if none found * @see #registerDefaultEditors */ + @Nullable public PropertyEditor getDefaultEditor(Class requiredType) { if (!this.defaultEditorsActive) { return null; @@ -336,7 +339,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry { * can be {@code null} if not known) * @return whether a matching custom editor has been found */ - public boolean hasCustomEditorForElement(Class elementType, String propertyPath) { + public boolean hasCustomEditorForElement(@Nullable Class elementType, @Nullable String propertyPath) { if (propertyPath != null && this.customEditorsForPath != null) { for (Map.Entry entry : this.customEditorsForPath.entrySet()) { if (PropertyAccessorUtils.matchesProperty(entry.getKey(), propertyPath)) { @@ -361,6 +364,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry { * @return the type of the property, or {@code null} if not determinable * @see BeanWrapper#getPropertyType(String) */ + @Nullable protected Class getPropertyType(String propertyPath) { return null; } @@ -371,6 +375,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry { * @param requiredType the type to look for * @return the custom editor, or {@code null} if none specific for this property */ + @Nullable private PropertyEditor getCustomEditor(String propertyName, Class requiredType) { CustomEditorHolder holder = this.customEditorsForPath.get(propertyName); return (holder != null ? holder.getPropertyEditor(requiredType) : null); @@ -384,6 +389,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry { * @return the custom editor, or {@code null} if none found for this type * @see java.beans.PropertyEditor#getAsText() */ + @Nullable private PropertyEditor getCustomEditor(Class requiredType) { if (requiredType == null || this.customEditors == null) { return null; @@ -420,6 +426,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry { * @param propertyName the name of the property * @return the property type, or {@code null} if not determinable */ + @Nullable protected Class guessPropertyTypeFromEditors(String propertyName) { if (this.customEditorsForPath != null) { CustomEditorHolder editorHolder = this.customEditorsForPath.get(propertyName); @@ -445,7 +452,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry { * If this is non-null, only editors registered for a path below this nested property * will be copied. If this is null, all editors will be copied. */ - protected void copyCustomEditorsTo(PropertyEditorRegistry target, String nestedProperty) { + protected void copyCustomEditorsTo(PropertyEditorRegistry target, @Nullable String nestedProperty) { String actualPropertyName = (nestedProperty != null ? PropertyAccessorUtils.getPropertyName(nestedProperty) : null); if (this.customEditors != null) { diff --git a/spring-beans/src/main/java/org/springframework/beans/PropertyValues.java b/spring-beans/src/main/java/org/springframework/beans/PropertyValues.java index 8af2c77ff7..cb2ac6cb17 100644 --- a/spring-beans/src/main/java/org/springframework/beans/PropertyValues.java +++ b/spring-beans/src/main/java/org/springframework/beans/PropertyValues.java @@ -16,6 +16,8 @@ package org.springframework.beans; +import org.springframework.lang.Nullable; + /** * Holder containing one or more {@link PropertyValue} objects, * typically comprising one update for a specific target bean. @@ -37,6 +39,7 @@ public interface PropertyValues { * @param propertyName the name to search for * @return the property value, or {@code null} */ + @Nullable PropertyValue getPropertyValue(String propertyName); /** diff --git a/spring-beans/src/main/java/org/springframework/beans/TypeConverter.java b/spring-beans/src/main/java/org/springframework/beans/TypeConverter.java index 6d69a63ce6..3cb9f6a5b1 100644 --- a/spring-beans/src/main/java/org/springframework/beans/TypeConverter.java +++ b/spring-beans/src/main/java/org/springframework/beans/TypeConverter.java @@ -19,6 +19,7 @@ package org.springframework.beans; import java.lang.reflect.Field; import org.springframework.core.MethodParameter; +import org.springframework.lang.Nullable; /** * Interface that defines type conversion methods. Typically (but not necessarily) @@ -49,7 +50,7 @@ public interface TypeConverter { * @see org.springframework.core.convert.ConversionService * @see org.springframework.core.convert.converter.Converter */ - T convertIfNecessary(Object value, Class requiredType) throws TypeMismatchException; + T convertIfNecessary(Object value, @Nullable Class requiredType) throws TypeMismatchException; /** * Convert the value to the required type (if necessary from a String). @@ -67,7 +68,7 @@ public interface TypeConverter { * @see org.springframework.core.convert.ConversionService * @see org.springframework.core.convert.converter.Converter */ - T convertIfNecessary(Object value, Class requiredType, MethodParameter methodParam) + T convertIfNecessary(Object value, @Nullable Class requiredType, @Nullable MethodParameter methodParam) throws TypeMismatchException; /** @@ -86,7 +87,7 @@ public interface TypeConverter { * @see org.springframework.core.convert.ConversionService * @see org.springframework.core.convert.converter.Converter */ - T convertIfNecessary(Object value, Class requiredType, Field field) + T convertIfNecessary(Object value, @Nullable Class requiredType, @Nullable Field field) throws TypeMismatchException; } diff --git a/spring-beans/src/main/java/org/springframework/beans/TypeConverterDelegate.java b/spring-beans/src/main/java/org/springframework/beans/TypeConverterDelegate.java index 9080d93f74..730f268910 100644 --- a/spring-beans/src/main/java/org/springframework/beans/TypeConverterDelegate.java +++ b/spring-beans/src/main/java/org/springframework/beans/TypeConverterDelegate.java @@ -34,6 +34,7 @@ import org.springframework.core.MethodParameter; import org.springframework.core.convert.ConversionFailedException; import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.TypeDescriptor; +import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.util.NumberUtils; import org.springframework.util.ReflectionUtils; @@ -90,7 +91,7 @@ class TypeConverterDelegate { * @return the new value, possibly the result of type conversion * @throws IllegalArgumentException if type conversion failed */ - public T convertIfNecessary(Object newValue, Class requiredType, MethodParameter methodParam) + public T convertIfNecessary(Object newValue, @Nullable Class requiredType, @Nullable MethodParameter methodParam) throws IllegalArgumentException { return convertIfNecessary(null, null, newValue, requiredType, @@ -107,7 +108,7 @@ class TypeConverterDelegate { * @return the new value, possibly the result of type conversion * @throws IllegalArgumentException if type conversion failed */ - public T convertIfNecessary(Object newValue, Class requiredType, Field field) + public T convertIfNecessary(Object newValue, @Nullable Class requiredType, @Nullable Field field) throws IllegalArgumentException { return convertIfNecessary(null, null, newValue, requiredType, @@ -125,7 +126,7 @@ class TypeConverterDelegate { * @throws IllegalArgumentException if type conversion failed */ public T convertIfNecessary( - String propertyName, Object oldValue, Object newValue, Class requiredType) + String propertyName, @Nullable Object oldValue, Object newValue, @Nullable Class requiredType) throws IllegalArgumentException { return convertIfNecessary(propertyName, oldValue, newValue, requiredType, TypeDescriptor.valueOf(requiredType)); @@ -144,8 +145,8 @@ class TypeConverterDelegate { * @throws IllegalArgumentException if type conversion failed */ @SuppressWarnings("unchecked") - public T convertIfNecessary(String propertyName, Object oldValue, Object newValue, - Class requiredType, TypeDescriptor typeDescriptor) throws IllegalArgumentException { + public T convertIfNecessary(String propertyName, @Nullable Object oldValue, Object newValue, + @Nullable Class requiredType, TypeDescriptor typeDescriptor) throws IllegalArgumentException { // Custom editor for this type? PropertyEditor editor = this.propertyEditorRegistry.findCustomEditor(requiredType, propertyName); @@ -357,6 +358,7 @@ class TypeConverterDelegate { * @param requiredType the type to find an editor for * @return the corresponding editor, or {@code null} if none */ + @Nullable private PropertyEditor findDefaultEditor(Class requiredType) { PropertyEditor editor = null; if (requiredType != null) { @@ -381,7 +383,7 @@ class TypeConverterDelegate { * @return the new value, possibly the result of type conversion * @throws IllegalArgumentException if type conversion failed */ - private Object doConvertValue(Object oldValue, Object newValue, Class requiredType, PropertyEditor editor) { + private Object doConvertValue(@Nullable Object oldValue, Object newValue, @Nullable Class requiredType, PropertyEditor editor) { Object convertedValue = newValue; if (editor != null && !(convertedValue instanceof String)) { @@ -443,7 +445,7 @@ class TypeConverterDelegate { * @param editor the PropertyEditor to use * @return the converted value */ - private Object doConvertTextValue(Object oldValue, String newTextValue, PropertyEditor editor) { + private Object doConvertTextValue(@Nullable Object oldValue, String newTextValue, PropertyEditor editor) { try { editor.setValue(oldValue); } diff --git a/spring-beans/src/main/java/org/springframework/beans/TypeMismatchException.java b/spring-beans/src/main/java/org/springframework/beans/TypeMismatchException.java index 2f81b70a41..2fe07446ab 100644 --- a/spring-beans/src/main/java/org/springframework/beans/TypeMismatchException.java +++ b/spring-beans/src/main/java/org/springframework/beans/TypeMismatchException.java @@ -18,6 +18,7 @@ package org.springframework.beans; import java.beans.PropertyChangeEvent; +import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; /** @@ -55,7 +56,7 @@ public class TypeMismatchException extends PropertyAccessException { * @param requiredType the required target type (or {@code null} if not known) * @param cause the root cause (may be {@code null}) */ - public TypeMismatchException(PropertyChangeEvent propertyChangeEvent, Class requiredType, Throwable cause) { + public TypeMismatchException(PropertyChangeEvent propertyChangeEvent, @Nullable Class requiredType, @Nullable Throwable cause) { super(propertyChangeEvent, "Failed to convert property value of type '" + ClassUtils.getDescriptiveType(propertyChangeEvent.getNewValue()) + "'" + @@ -73,7 +74,7 @@ public class TypeMismatchException extends PropertyAccessException { * @param value the offending value that couldn't be converted (may be {@code null}) * @param requiredType the required target type (or {@code null} if not known) */ - public TypeMismatchException(Object value, Class requiredType) { + public TypeMismatchException(@Nullable Object value, @Nullable Class requiredType) { this(value, requiredType, null); } @@ -83,7 +84,7 @@ public class TypeMismatchException extends PropertyAccessException { * @param requiredType the required target type (or {@code null} if not known) * @param cause the root cause (may be {@code null}) */ - public TypeMismatchException(Object value, Class requiredType, Throwable cause) { + public TypeMismatchException(@Nullable Object value, @Nullable Class requiredType, @Nullable Throwable cause) { 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 { /** * Return the required target type, if any. */ + @Nullable public Class getRequiredType() { return this.requiredType; } diff --git a/spring-beans/src/main/java/org/springframework/beans/annotation/AnnotationBeanUtils.java b/spring-beans/src/main/java/org/springframework/beans/annotation/AnnotationBeanUtils.java index 55dca06c30..6f5a198b7d 100644 --- a/spring-beans/src/main/java/org/springframework/beans/annotation/AnnotationBeanUtils.java +++ b/spring-beans/src/main/java/org/springframework/beans/annotation/AnnotationBeanUtils.java @@ -24,6 +24,7 @@ import java.util.Set; import org.springframework.beans.BeanWrapper; import org.springframework.beans.PropertyAccessorFactory; +import org.springframework.lang.Nullable; import org.springframework.util.ReflectionUtils; import org.springframework.util.StringValueResolver; @@ -44,7 +45,7 @@ public abstract class AnnotationBeanUtils { * @param excludedProperties the names of excluded properties, if any * @see org.springframework.beans.BeanWrapper */ - public static void copyPropertiesToBean(Annotation ann, Object bean, String... excludedProperties) { + public static void copyPropertiesToBean(Annotation ann, Object bean, @Nullable String... excludedProperties) { copyPropertiesToBean(ann, bean, null, excludedProperties); } @@ -58,7 +59,7 @@ public abstract class AnnotationBeanUtils { * @param excludedProperties the names of excluded properties, if any * @see org.springframework.beans.BeanWrapper */ - public static void copyPropertiesToBean(Annotation ann, Object bean, StringValueResolver valueResolver, String... excludedProperties) { + public static void copyPropertiesToBean(Annotation ann, Object bean, @Nullable StringValueResolver valueResolver, @Nullable String... excludedProperties) { Set excluded = new HashSet<>(Arrays.asList(excludedProperties)); Method[] annotationProperties = ann.annotationType().getDeclaredMethods(); BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(bean); diff --git a/spring-beans/src/main/java/org/springframework/beans/annotation/package-info.java b/spring-beans/src/main/java/org/springframework/beans/annotation/package-info.java index 004728944b..113e56cfb6 100644 --- a/spring-beans/src/main/java/org/springframework/beans/annotation/package-info.java +++ b/spring-beans/src/main/java/org/springframework/beans/annotation/package-info.java @@ -1,4 +1,7 @@ /** * Support package for beans-style handling of Java 5 annotations. */ +@NonNullApi package org.springframework.beans.annotation; + +import org.springframework.lang.NonNullApi; diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/BeanClassLoaderAware.java b/spring-beans/src/main/java/org/springframework/beans/factory/BeanClassLoaderAware.java index e207fdb3c8..5249a93e4c 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/BeanClassLoaderAware.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/BeanClassLoaderAware.java @@ -16,6 +16,8 @@ package org.springframework.beans.factory; +import org.springframework.lang.Nullable; + /** * Callback that allows a bean to be aware of the bean * {@link ClassLoader class loader}; that is, the class loader used by the @@ -50,6 +52,6 @@ public interface BeanClassLoaderAware extends Aware { * the {@code ClassLoader} obtained via * {@link org.springframework.util.ClassUtils#getDefaultClassLoader()} */ - void setBeanClassLoader(ClassLoader classLoader); + void setBeanClassLoader(@Nullable ClassLoader classLoader); } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/BeanCreationException.java b/spring-beans/src/main/java/org/springframework/beans/factory/BeanCreationException.java index 9a746f2ff2..16b2966c7f 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/BeanCreationException.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/BeanCreationException.java @@ -23,6 +23,7 @@ import java.util.List; import org.springframework.beans.FatalBeanException; import org.springframework.core.NestedRuntimeException; +import org.springframework.lang.Nullable; /** * Exception thrown when a BeanFactory encounters an error when @@ -109,6 +110,7 @@ public class BeanCreationException extends FatalBeanException { /** * Return the name of the bean requested, if any. */ + @Nullable public String getBeanName() { return this.beanName; } @@ -117,6 +119,7 @@ public class BeanCreationException extends FatalBeanException { * Return the description of the resource that the bean * definition came from, if any. */ + @Nullable public String getResourceDescription() { return this.resourceDescription; } @@ -138,6 +141,7 @@ public class BeanCreationException extends FatalBeanException { * Return the related causes, if any. * @return the array of related causes, or {@code null} if none */ + @Nullable public Throwable[] getRelatedCauses() { if (this.relatedCauses == null) { return null; diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/BeanDefinitionStoreException.java b/spring-beans/src/main/java/org/springframework/beans/factory/BeanDefinitionStoreException.java index 47a2ec8c14..a870277500 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/BeanDefinitionStoreException.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/BeanDefinitionStoreException.java @@ -17,6 +17,7 @@ package org.springframework.beans.factory; import org.springframework.beans.FatalBeanException; +import org.springframework.lang.Nullable; /** * Exception thrown when a BeanFactory encounters an invalid bean definition: @@ -47,7 +48,7 @@ public class BeanDefinitionStoreException extends FatalBeanException { * @param msg the detail message (used as exception message as-is) * @param cause the root cause (may be {@code null}) */ - public BeanDefinitionStoreException(String msg, Throwable cause) { + public BeanDefinitionStoreException(String msg, @Nullable Throwable cause) { super(msg, cause); } @@ -67,7 +68,7 @@ public class BeanDefinitionStoreException extends FatalBeanException { * @param msg the detail message (used as exception message as-is) * @param cause the root cause (may be {@code null}) */ - public BeanDefinitionStoreException(String resourceDescription, String msg, Throwable cause) { + public BeanDefinitionStoreException(String resourceDescription, String msg, @Nullable Throwable cause) { super(msg, cause); this.resourceDescription = resourceDescription; } @@ -91,7 +92,7 @@ public class BeanDefinitionStoreException extends FatalBeanException { * the resource and the name of the bean) * @param cause the root cause (may be {@code null}) */ - public BeanDefinitionStoreException(String resourceDescription, String beanName, String msg, Throwable cause) { + public BeanDefinitionStoreException(String resourceDescription, String beanName, String msg, @Nullable Throwable cause) { 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 { * Return the description of the resource that the bean * definition came from, if any. */ + @Nullable public String getResourceDescription() { return this.resourceDescription; } @@ -109,6 +111,7 @@ public class BeanDefinitionStoreException extends FatalBeanException { /** * Return the name of the bean requested, if any. */ + @Nullable public String getBeanName() { return this.beanName; } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/BeanFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/BeanFactory.java index f3e418abb2..c0837c6dcc 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/BeanFactory.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/BeanFactory.java @@ -18,6 +18,7 @@ package org.springframework.beans.factory; import org.springframework.beans.BeansException; import org.springframework.core.ResolvableType; +import org.springframework.lang.Nullable; /** * The root interface for accessing a Spring bean container. @@ -156,7 +157,7 @@ public interface BeanFactory { * @throws BeanNotOfRequiredTypeException if the bean is not of the required type * @throws BeansException if the bean could not be created */ - T getBean(String name, Class requiredType) throws BeansException; + T getBean(String name, @Nullable Class requiredType) throws BeansException; /** * Return the bean instance that uniquely matches the given object type, if any. @@ -313,6 +314,7 @@ public interface BeanFactory { * @see #getBean * @see #isTypeMatch */ + @Nullable Class getType(String name) throws NoSuchBeanDefinitionException; /** diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/FactoryBean.java b/spring-beans/src/main/java/org/springframework/beans/factory/FactoryBean.java index 1f45088ec9..78c008c297 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/FactoryBean.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/FactoryBean.java @@ -16,6 +16,8 @@ package org.springframework.beans.factory; +import org.springframework.lang.Nullable; + /** * Interface to be implemented by objects used within a {@link BeanFactory} which * are themselves factories for individual objects. If a bean implements this @@ -72,6 +74,7 @@ public interface FactoryBean { * @throws Exception in case of creation errors * @see FactoryBeanNotInitializedException */ + @Nullable T getObject() throws Exception; /** @@ -93,6 +96,7 @@ public interface FactoryBean { * or {@code null} if not known at the time of the call * @see ListableBeanFactory#getBeansOfType */ + @Nullable Class getObjectType(); /** diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/HierarchicalBeanFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/HierarchicalBeanFactory.java index 7e6a347afc..2860411b75 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/HierarchicalBeanFactory.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/HierarchicalBeanFactory.java @@ -16,6 +16,8 @@ package org.springframework.beans.factory; +import org.springframework.lang.Nullable; + /** * Sub-interface implemented by bean factories that can be part * of a hierarchy. @@ -34,6 +36,7 @@ public interface HierarchicalBeanFactory extends BeanFactory { /** * Return the parent bean factory, or {@code null} if there is none. */ + @Nullable BeanFactory getParentBeanFactory(); /** diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/InjectionPoint.java b/spring-beans/src/main/java/org/springframework/beans/factory/InjectionPoint.java index 38ace23fd4..f129577052 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/InjectionPoint.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/InjectionPoint.java @@ -22,6 +22,7 @@ import java.lang.reflect.Field; import java.lang.reflect.Member; import org.springframework.core.MethodParameter; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -83,6 +84,7 @@ public class InjectionPoint { *

Note: Either MethodParameter or Field is available. * @return the MethodParameter, or {@code null} if none */ + @Nullable public MethodParameter getMethodParameter() { return this.methodParameter; } @@ -92,6 +94,7 @@ public class InjectionPoint { *

Note: Either MethodParameter or Field is available. * @return the Field, or {@code null} if none */ + @Nullable public Field getField() { return this.field; } @@ -117,6 +120,7 @@ public class InjectionPoint { * @return the annotation instance, or {@code null} if none found * @since 4.3.9 */ + @Nullable public A getAnnotation(Class annotationType) { return (this.field != null ? this.field.getAnnotation(annotationType) : this.methodParameter.getParameterAnnotation(annotationType)); diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/ListableBeanFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/ListableBeanFactory.java index e8be332289..4b7dea51cd 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/ListableBeanFactory.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/ListableBeanFactory.java @@ -21,6 +21,7 @@ import java.util.Map; import org.springframework.beans.BeansException; import org.springframework.core.ResolvableType; +import org.springframework.lang.Nullable; /** * Extension of the {@link BeanFactory} interface to be implemented by bean factories @@ -113,7 +114,7 @@ public interface ListableBeanFactory extends BeanFactory { * @see FactoryBean#getObjectType * @see BeanFactoryUtils#beanNamesForTypeIncludingAncestors(ListableBeanFactory, ResolvableType) */ - String[] getBeanNamesForType(ResolvableType type); + String[] getBeanNamesForType(@Nullable ResolvableType type); /** * Return the names of beans matching the given type (including subclasses), @@ -140,7 +141,7 @@ public interface ListableBeanFactory extends BeanFactory { * @see FactoryBean#getObjectType * @see BeanFactoryUtils#beanNamesForTypeIncludingAncestors(ListableBeanFactory, Class) */ - String[] getBeanNamesForType(Class type); + String[] getBeanNamesForType(@Nullable Class type); /** * Return the names of beans matching the given type (including subclasses), @@ -173,7 +174,7 @@ public interface ListableBeanFactory extends BeanFactory { * @see FactoryBean#getObjectType * @see BeanFactoryUtils#beanNamesForTypeIncludingAncestors(ListableBeanFactory, Class, boolean, boolean) */ - String[] getBeanNamesForType(Class type, boolean includeNonSingletons, boolean allowEagerInit); + String[] getBeanNamesForType(@Nullable Class type, boolean includeNonSingletons, boolean allowEagerInit); /** * Return the bean instances that match the given object type (including @@ -203,7 +204,7 @@ public interface ListableBeanFactory extends BeanFactory { * @see FactoryBean#getObjectType * @see BeanFactoryUtils#beansOfTypeIncludingAncestors(ListableBeanFactory, Class) */ - Map getBeansOfType(Class type) throws BeansException; + Map getBeansOfType(@Nullable Class type) throws BeansException; /** * Return the bean instances that match the given object type (including @@ -238,7 +239,7 @@ public interface ListableBeanFactory extends BeanFactory { * @see FactoryBean#getObjectType * @see BeanFactoryUtils#beansOfTypeIncludingAncestors(ListableBeanFactory, Class, boolean, boolean) */ - Map getBeansOfType(Class type, boolean includeNonSingletons, boolean allowEagerInit) + Map getBeansOfType(@Nullable Class type, boolean includeNonSingletons, boolean allowEagerInit) throws BeansException; /** @@ -271,6 +272,7 @@ public interface ListableBeanFactory extends BeanFactory { * @throws NoSuchBeanDefinitionException if there is no bean with the given name * @since 3.0 */ + @Nullable A findAnnotationOnBean(String beanName, Class annotationType) throws NoSuchBeanDefinitionException; diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/NoUniqueBeanDefinitionException.java b/spring-beans/src/main/java/org/springframework/beans/factory/NoUniqueBeanDefinitionException.java index 6bb4f6dbc0..02617c8fe9 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/NoUniqueBeanDefinitionException.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/NoUniqueBeanDefinitionException.java @@ -19,6 +19,7 @@ package org.springframework.beans.factory; import java.util.Arrays; import java.util.Collection; +import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; /** @@ -85,6 +86,7 @@ public class NoUniqueBeanDefinitionException extends NoSuchBeanDefinitionExcepti * @since 4.3 * @see #getBeanType() */ + @Nullable public Collection getBeanNamesFound() { return this.beanNamesFound; } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/ObjectProvider.java b/spring-beans/src/main/java/org/springframework/beans/factory/ObjectProvider.java index 7bc61f87f7..de71971894 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/ObjectProvider.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/ObjectProvider.java @@ -19,6 +19,7 @@ package org.springframework.beans.factory; import java.util.function.Supplier; import org.springframework.beans.BeansException; +import org.springframework.lang.Nullable; /** * A variant of {@link ObjectFactory} designed specifically for injection points, @@ -48,6 +49,7 @@ public interface ObjectProvider extends ObjectFactory { * @throws BeansException in case of creation errors * @see #getObject() */ + @Nullable T getIfAvailable() throws BeansException; /** @@ -74,6 +76,7 @@ public interface ObjectProvider extends ObjectFactory { * @throws BeansException in case of creation errors * @see #getObject() */ + @Nullable T getIfUnique() throws BeansException; /** diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AnnotatedBeanDefinition.java b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AnnotatedBeanDefinition.java index befb411860..dd59fbc6a5 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AnnotatedBeanDefinition.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AnnotatedBeanDefinition.java @@ -19,6 +19,7 @@ package org.springframework.beans.factory.annotation; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.core.type.AnnotationMetadata; import org.springframework.core.type.MethodMetadata; +import org.springframework.lang.Nullable; /** * Extended {@link org.springframework.beans.factory.config.BeanDefinition} @@ -44,6 +45,7 @@ public interface AnnotatedBeanDefinition extends BeanDefinition { * @return the factory method metadata, or {@code null} if none * @since 4.1.1 */ + @Nullable MethodMetadata getFactoryMethodMetadata(); } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java index de10ab8726..f763aad22c 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java @@ -60,6 +60,7 @@ import org.springframework.core.Ordered; import org.springframework.core.PriorityOrdered; import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.core.annotation.AnnotationAttributes; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.ReflectionUtils; @@ -468,6 +469,7 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean return new InjectionMetadata(clazz, elements); } + @Nullable private AnnotationAttributes findAutowiredAnnotation(AccessibleObject ao) { if (ao.getAnnotations().length > 0) { for (Class type : this.autowiredAnnotationTypes) { @@ -691,6 +693,7 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean } } + @Nullable private Object[] resolveCachedArguments(String beanName) { if (this.cachedMethodArguments == null) { return null; diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/InjectionMetadata.java b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/InjectionMetadata.java index f60e7e6f2d..7021f8c3ab 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/InjectionMetadata.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/InjectionMetadata.java @@ -31,6 +31,7 @@ import org.apache.commons.logging.LogFactory; import org.springframework.beans.MutablePropertyValues; import org.springframework.beans.PropertyValues; import org.springframework.beans.factory.support.RootBeanDefinition; +import org.springframework.lang.Nullable; import org.springframework.util.ReflectionUtils; /** @@ -232,6 +233,7 @@ public class InjectionMetadata { /** * Either this or {@link #inject} needs to be overridden. */ + @Nullable protected Object getResourceToInject(Object target, String requestingBeanName) { return null; } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/QualifierAnnotationAutowireCandidateResolver.java b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/QualifierAnnotationAutowireCandidateResolver.java index 46c42853c1..e33fd4c889 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/QualifierAnnotationAutowireCandidateResolver.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/QualifierAnnotationAutowireCandidateResolver.java @@ -36,6 +36,7 @@ import org.springframework.core.MethodParameter; import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.core.annotation.AnnotationAttributes; import org.springframework.core.annotation.AnnotationUtils; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.ObjectUtils; @@ -341,6 +342,7 @@ public class QualifierAnnotationAutowireCandidateResolver extends GenericTypeAwa /** * Determine a suggested value from any of the given candidate annotations. */ + @Nullable protected Object findValue(Annotation[] annotationsToSearch) { AnnotationAttributes attr = AnnotatedElementUtils.getMergedAnnotationAttributes( AnnotatedElementUtils.forAnnotations(annotationsToSearch), this.valueAnnotationType); diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/package-info.java b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/package-info.java index 19c01c942e..aada302b81 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/package-info.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/package-info.java @@ -1,4 +1,7 @@ /** * Support package for annotation-driven bean configuration. */ +@NonNullApi package org.springframework.beans.factory.annotation; + +import org.springframework.lang.NonNullApi; diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/AbstractFactoryBean.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/AbstractFactoryBean.java index 85faab006b..625bb2cd5f 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/AbstractFactoryBean.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/AbstractFactoryBean.java @@ -33,6 +33,7 @@ import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.FactoryBeanNotInitializedException; import org.springframework.beans.factory.InitializingBean; +import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.util.ObjectUtils; import org.springframework.util.ReflectionUtils; @@ -225,6 +226,7 @@ public abstract class AbstractFactoryBean * or {@code null} to indicate a FactoryBeanNotInitializedException * @see org.springframework.beans.factory.FactoryBeanNotInitializedException */ + @Nullable protected Class[] getEarlySingletonInterfaces() { Class type = getObjectType(); return (type != null && type.isInterface() ? new Class[] {type} : null); diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/AutowireCapableBeanFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/AutowireCapableBeanFactory.java index 61b5240770..fed381c401 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/AutowireCapableBeanFactory.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/AutowireCapableBeanFactory.java @@ -23,6 +23,7 @@ import org.springframework.beans.TypeConverter; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.beans.factory.NoUniqueBeanDefinitionException; +import org.springframework.lang.Nullable; /** * Extension of the {@link org.springframework.beans.factory.BeanFactory} @@ -337,6 +338,7 @@ public interface AutowireCapableBeanFactory extends BeanFactory { * @since 2.5 * @see #resolveDependency(DependencyDescriptor, String, Set, TypeConverter) */ + @Nullable Object resolveDependency(DependencyDescriptor descriptor, String requestingBeanName) throws BeansException; /** @@ -353,6 +355,7 @@ public interface AutowireCapableBeanFactory extends BeanFactory { * @since 2.5 * @see DependencyDescriptor */ + @Nullable Object resolveDependency(DependencyDescriptor descriptor, String requestingBeanName, Set autowiredBeanNames, TypeConverter typeConverter) throws BeansException; diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/BeanDefinition.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/BeanDefinition.java index c9e0db6ad8..8cd218573f 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/BeanDefinition.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/BeanDefinition.java @@ -19,6 +19,7 @@ package org.springframework.beans.factory.config; import org.springframework.beans.BeanMetadataElement; import org.springframework.beans.MutablePropertyValues; import org.springframework.core.AttributeAccessor; +import org.springframework.lang.Nullable; /** * A BeanDefinition describes a bean instance, which has property values, @@ -84,11 +85,12 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement { /** * Set the name of the parent definition of this bean definition, if any. */ - void setParentName(String parentName); + void setParentName(@Nullable String parentName); /** * Return the name of the parent definition of this bean definition, if any. */ + @Nullable String getParentName(); /** @@ -126,6 +128,7 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement { * Return the name of the current target scope for this bean, * or {@code null} if not known yet. */ + @Nullable String getScope(); /** @@ -188,6 +191,7 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement { /** * Return the factory bean name, if any. */ + @Nullable String getFactoryBeanName(); /** @@ -203,6 +207,7 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement { /** * Return a factory method, if any. */ + @Nullable String getFactoryMethodName(); /** @@ -260,6 +265,7 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement { * Return a description of the resource that this bean definition * came from (for the purpose of showing context in case of errors). */ + @Nullable String getResourceDescription(); /** @@ -268,6 +274,7 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement { *

Note that this method returns the immediate originator. Iterate through the * originator chain to find the original BeanDefinition as defined by the user. */ + @Nullable BeanDefinition getOriginatingBeanDefinition(); } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/BeanDefinitionHolder.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/BeanDefinitionHolder.java index 6e10d7573a..9379a831af 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/BeanDefinitionHolder.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/BeanDefinitionHolder.java @@ -18,6 +18,7 @@ package org.springframework.beans.factory.config; import org.springframework.beans.BeanMetadataElement; import org.springframework.beans.factory.BeanFactoryUtils; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; @@ -60,7 +61,7 @@ public class BeanDefinitionHolder implements BeanMetadataElement { * @param beanName the name of the bean, as specified for the bean definition * @param aliases alias names for the bean, or {@code null} if none */ - public BeanDefinitionHolder(BeanDefinition beanDefinition, String beanName, String[] aliases) { + public BeanDefinitionHolder(BeanDefinition beanDefinition, String beanName, @Nullable String[] aliases) { Assert.notNull(beanDefinition, "BeanDefinition must not be null"); Assert.notNull(beanName, "Bean name must not be null"); this.beanDefinition = beanDefinition; @@ -101,6 +102,7 @@ public class BeanDefinitionHolder implements BeanMetadataElement { * Return the alias names for the bean, as specified directly for the bean definition. * @return the array of alias names, or {@code null} if none */ + @Nullable public String[] getAliases() { return this.aliases; } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/BeanExpressionContext.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/BeanExpressionContext.java index 1da52f0e20..2f0a5bead2 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/BeanExpressionContext.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/BeanExpressionContext.java @@ -16,6 +16,7 @@ package org.springframework.beans.factory.config; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -51,6 +52,7 @@ public class BeanExpressionContext { (this.scope != null && this.scope.resolveContextualObject(key) != null)); } + @Nullable public Object getObject(String key) { if (this.beanFactory.containsBean(key)) { return this.beanFactory.getBean(key); diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/BeanPostProcessor.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/BeanPostProcessor.java index ce61b2de93..7121908cf0 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/BeanPostProcessor.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/BeanPostProcessor.java @@ -17,6 +17,7 @@ package org.springframework.beans.factory.config; import org.springframework.beans.BeansException; +import org.springframework.lang.Nullable; /** * Factory hook that allows for custom modification of new bean instances, @@ -54,6 +55,7 @@ public interface BeanPostProcessor { * @throws org.springframework.beans.BeansException in case of errors * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet */ + @Nullable default Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { return bean; } @@ -79,6 +81,7 @@ public interface BeanPostProcessor { * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet * @see org.springframework.beans.factory.FactoryBean */ + @Nullable default Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { return bean; } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/ConfigurableBeanFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/ConfigurableBeanFactory.java index 302deec58f..35f5b860b4 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/ConfigurableBeanFactory.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/ConfigurableBeanFactory.java @@ -27,6 +27,7 @@ import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.HierarchicalBeanFactory; import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.core.convert.ConversionService; +import org.springframework.lang.Nullable; import org.springframework.util.StringValueResolver; /** @@ -85,7 +86,7 @@ public interface ConfigurableBeanFactory extends HierarchicalBeanFactory, Single * @param beanClassLoader the class loader to use, * or {@code null} to suggest the default class loader */ - void setBeanClassLoader(ClassLoader beanClassLoader); + void setBeanClassLoader(@Nullable ClassLoader beanClassLoader); /** * Return this factory's class loader for loading bean classes. @@ -108,6 +109,7 @@ public interface ConfigurableBeanFactory extends HierarchicalBeanFactory, Single * if any. * @since 2.5 */ + @Nullable ClassLoader getTempClassLoader(); /** @@ -151,6 +153,7 @@ public interface ConfigurableBeanFactory extends HierarchicalBeanFactory, Single * Return the associated ConversionService, if any. * @since 3.0 */ + @Nullable ConversionService getConversionService(); /** @@ -222,6 +225,7 @@ public interface ConfigurableBeanFactory extends HierarchicalBeanFactory, Single * @return the resolved value (may be the original value as-is) * @since 3.0 */ + @Nullable String resolveEmbeddedValue(String value); /** @@ -265,6 +269,7 @@ public interface ConfigurableBeanFactory extends HierarchicalBeanFactory, Single * @return the registered Scope implementation, or {@code null} if none * @see #registerScope */ + @Nullable Scope getRegisteredScope(String scopeName); /** diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/ConstructorArgumentValues.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/ConstructorArgumentValues.java index dfffe28e36..87efa185e5 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/ConstructorArgumentValues.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/ConstructorArgumentValues.java @@ -26,6 +26,7 @@ import java.util.Set; import org.springframework.beans.BeanMetadataElement; import org.springframework.beans.Mergeable; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.ObjectUtils; @@ -146,7 +147,8 @@ public class ConstructorArgumentValues { * untyped values only) * @return the ValueHolder for the argument, or {@code null} if none set */ - public ValueHolder getIndexedArgumentValue(int index, Class requiredType) { + @Nullable + public ValueHolder getIndexedArgumentValue(int index, @Nullable Class requiredType) { return getIndexedArgumentValue(index, requiredType, null); } @@ -159,7 +161,8 @@ public class ConstructorArgumentValues { * unnamed values only, or empty String to match any name) * @return the ValueHolder for the argument, or {@code null} if none set */ - public ValueHolder getIndexedArgumentValue(int index, Class requiredType, String requiredName) { + @Nullable + public ValueHolder getIndexedArgumentValue(int index, @Nullable Class requiredType, @Nullable String requiredName) { Assert.isTrue(index >= 0, "Index must not be negative"); ValueHolder valueHolder = this.indexedArgumentValues.get(index); if (valueHolder != null && @@ -247,6 +250,7 @@ public class ConstructorArgumentValues { * @param requiredType the type to match * @return the ValueHolder for the argument, or {@code null} if none set */ + @Nullable public ValueHolder getGenericArgumentValue(Class requiredType) { return getGenericArgumentValue(requiredType, null, null); } @@ -257,6 +261,7 @@ public class ConstructorArgumentValues { * @param requiredName the name to match * @return the ValueHolder for the argument, or {@code null} if none set */ + @Nullable public ValueHolder getGenericArgumentValue(Class requiredType, String requiredName) { return getGenericArgumentValue(requiredType, requiredName, null); } @@ -273,7 +278,8 @@ public class ConstructorArgumentValues { * in the current resolution process and should therefore not be returned again * @return the ValueHolder for the argument, or {@code null} if none found */ - public ValueHolder getGenericArgumentValue(Class requiredType, String requiredName, Set usedValueHolders) { + @Nullable + public ValueHolder getGenericArgumentValue(@Nullable Class requiredType, @Nullable String requiredName, Set usedValueHolders) { for (ValueHolder valueHolder : this.genericArgumentValues) { if (usedValueHolders != null && usedValueHolders.contains(valueHolder)) { continue; @@ -312,6 +318,7 @@ public class ConstructorArgumentValues { * @param requiredType the parameter type to match * @return the ValueHolder for the argument, or {@code null} if none set */ + @Nullable public ValueHolder getArgumentValue(int index, Class requiredType) { return getArgumentValue(index, requiredType, null, null); } @@ -324,6 +331,7 @@ public class ConstructorArgumentValues { * @param requiredName the parameter name to match * @return the ValueHolder for the argument, or {@code null} if none set */ + @Nullable public ValueHolder getArgumentValue(int index, Class requiredType, String requiredName) { return getArgumentValue(index, requiredType, requiredName, null); } @@ -342,7 +350,8 @@ public class ConstructorArgumentValues { * in case of multiple generic argument values of the same type) * @return the ValueHolder for the argument, or {@code null} if none set */ - public ValueHolder getArgumentValue(int index, Class requiredType, String requiredName, Set usedValueHolders) { + @Nullable + public ValueHolder getArgumentValue(int index, @Nullable Class requiredType, @Nullable String requiredName, Set usedValueHolders) { Assert.isTrue(index >= 0, "Index must not be negative"); ValueHolder valueHolder = getIndexedArgumentValue(index, requiredType, requiredName); if (valueHolder == null) { diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/DependencyDescriptor.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/DependencyDescriptor.java index 7d19ad3481..3b6288fc3b 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/DependencyDescriptor.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/DependencyDescriptor.java @@ -38,6 +38,7 @@ import org.springframework.core.GenericTypeResolver; import org.springframework.core.MethodParameter; import org.springframework.core.ParameterNameDiscoverer; import org.springframework.core.ResolvableType; +import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; /** @@ -211,6 +212,7 @@ public class DependencyDescriptor extends InjectionPoint implements Serializable * @throws BeansException in case of the not-unique scenario being fatal * @since 4.3 */ + @Nullable public Object resolveNotUnique(Class type, Map matchingBeans) throws BeansException { throw new NoUniqueBeanDefinitionException(type, matchingBeans.keySet()); } @@ -227,6 +229,7 @@ public class DependencyDescriptor extends InjectionPoint implements Serializable * @throws BeansException if the shortcut could not be obtained * @since 4.3.1 */ + @Nullable public Object resolveShortcut(BeanFactory beanFactory) throws BeansException { return null; } @@ -321,7 +324,7 @@ public class DependencyDescriptor extends InjectionPoint implements Serializable * this point; it just allows discovery to happen when the application calls * {@link #getDependencyName()} (if ever). */ - public void initParameterNameDiscovery(ParameterNameDiscoverer parameterNameDiscoverer) { + public void initParameterNameDiscovery(@Nullable ParameterNameDiscoverer parameterNameDiscoverer) { if (this.methodParameter != null) { this.methodParameter.initParameterNameDiscovery(parameterNameDiscoverer); } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/InstantiationAwareBeanPostProcessor.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/InstantiationAwareBeanPostProcessor.java index 595707fe76..ca664f40ad 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/InstantiationAwareBeanPostProcessor.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/InstantiationAwareBeanPostProcessor.java @@ -20,6 +20,7 @@ import java.beans.PropertyDescriptor; import org.springframework.beans.BeansException; import org.springframework.beans.PropertyValues; +import org.springframework.lang.Nullable; /** * Subinterface of {@link BeanPostProcessor} that adds a before-instantiation callback, @@ -67,6 +68,7 @@ public interface InstantiationAwareBeanPostProcessor extends BeanPostProcessor { * @see org.springframework.beans.factory.support.AbstractBeanDefinition#hasBeanClass * @see org.springframework.beans.factory.support.AbstractBeanDefinition#getFactoryMethodName */ + @Nullable default Object postProcessBeforeInstantiation(Class beanClass, String beanName) throws BeansException { return null; } @@ -109,6 +111,7 @@ public interface InstantiationAwareBeanPostProcessor extends BeanPostProcessor { * @throws org.springframework.beans.BeansException in case of errors * @see org.springframework.beans.MutablePropertyValues */ + @Nullable default PropertyValues postProcessPropertyValues( PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName) throws BeansException { diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/NamedBeanHolder.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/NamedBeanHolder.java index 04e5e39a37..0c43b97c31 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/NamedBeanHolder.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/NamedBeanHolder.java @@ -17,6 +17,7 @@ package org.springframework.beans.factory.config; import org.springframework.beans.factory.NamedBean; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -56,6 +57,7 @@ public class NamedBeanHolder implements NamedBean { /** * Return the corresponding bean instance (can be {@code null}). */ + @Nullable public T getBeanInstance() { return this.beanInstance; } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/PlaceholderConfigurerSupport.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/PlaceholderConfigurerSupport.java index f7223a9a1c..91ec753eee 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/PlaceholderConfigurerSupport.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/PlaceholderConfigurerSupport.java @@ -20,6 +20,7 @@ import org.springframework.beans.factory.BeanDefinitionStoreException; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.beans.factory.BeanNameAware; +import org.springframework.lang.Nullable; import org.springframework.util.StringValueResolver; /** @@ -140,7 +141,7 @@ public abstract class PlaceholderConfigurerSupport extends PropertyResourceConfi * special character should be processed as a value separator. * The default is {@value #DEFAULT_VALUE_SEPARATOR}. */ - public void setValueSeparator(String valueSeparator) { + public void setValueSeparator(@Nullable String valueSeparator) { this.valueSeparator = valueSeparator; } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/PreferencesPlaceholderConfigurer.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/PreferencesPlaceholderConfigurer.java index c8de04029b..89f41a126d 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/PreferencesPlaceholderConfigurer.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/PreferencesPlaceholderConfigurer.java @@ -22,6 +22,7 @@ import java.util.prefs.Preferences; import org.springframework.beans.factory.BeanDefinitionStoreException; import org.springframework.beans.factory.InitializingBean; +import org.springframework.lang.Nullable; /** * Subclass of PropertyPlaceholderConfigurer that supports JDK 1.4's @@ -113,6 +114,7 @@ public class PreferencesPlaceholderConfigurer extends PropertyPlaceholderConfigu * @param preferences the Preferences to resolve against * @return the value for the placeholder, or {@code null} if none found */ + @Nullable protected String resolvePlaceholder(String path, String key, Preferences preferences) { if (path != null) { // Do not create the node if it does not exist... diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/PropertyPlaceholderConfigurer.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/PropertyPlaceholderConfigurer.java index 39129c60a7..6a21805217 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/PropertyPlaceholderConfigurer.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/PropertyPlaceholderConfigurer.java @@ -22,6 +22,7 @@ import org.springframework.beans.BeansException; import org.springframework.core.Constants; import org.springframework.core.SpringProperties; import org.springframework.core.env.AbstractEnvironment; +import org.springframework.lang.Nullable; import org.springframework.util.PropertyPlaceholderHelper; import org.springframework.util.PropertyPlaceholderHelper.PlaceholderResolver; import org.springframework.util.StringValueResolver; @@ -179,6 +180,7 @@ public class PropertyPlaceholderConfigurer extends PlaceholderConfigurerSupport * @return the resolved value, of {@code null} if none * @see #setSystemPropertiesMode */ + @Nullable protected String resolvePlaceholder(String placeholder, Properties props) { return props.getProperty(placeholder); } @@ -192,6 +194,7 @@ public class PropertyPlaceholderConfigurer extends PlaceholderConfigurerSupport * @see System#getProperty(String) * @see System#getenv(String) */ + @Nullable protected String resolveSystemProperty(String key) { try { String value = System.getProperty(key); diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/Scope.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/Scope.java index 4e313c7919..aebaf3135f 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/Scope.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/Scope.java @@ -17,6 +17,7 @@ package org.springframework.beans.factory.config; import org.springframework.beans.factory.ObjectFactory; +import org.springframework.lang.Nullable; /** * Strategy interface used by a {@link ConfigurableBeanFactory}, @@ -88,6 +89,7 @@ public interface Scope { * @throws IllegalStateException if the underlying scope is not currently active * @see #registerDestructionCallback */ + @Nullable Object remove(String name); /** @@ -128,6 +130,7 @@ public interface Scope { * @return the corresponding object, or {@code null} if none found * @throws IllegalStateException if the underlying scope is not currently active */ + @Nullable Object resolveContextualObject(String key); /** @@ -145,6 +148,7 @@ public interface Scope { * conversation ID for the current scope * @throws IllegalStateException if the underlying scope is not currently active */ + @Nullable String getConversationId(); } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/SingletonBeanRegistry.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/SingletonBeanRegistry.java index e2188050f1..f610c8d815 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/SingletonBeanRegistry.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/SingletonBeanRegistry.java @@ -16,6 +16,8 @@ package org.springframework.beans.factory.config; +import org.springframework.lang.Nullable; + /** * Interface that defines a registry for shared bean instances. * Can be implemented by {@link org.springframework.beans.factory.BeanFactory} @@ -68,6 +70,7 @@ public interface SingletonBeanRegistry { * @return the registered singleton object, or {@code null} if none found * @see ConfigurableListableBeanFactory#getBeanDefinition */ + @Nullable Object getSingleton(String beanName); /** diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/SmartInstantiationAwareBeanPostProcessor.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/SmartInstantiationAwareBeanPostProcessor.java index 61a0a8f666..5d52fae329 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/SmartInstantiationAwareBeanPostProcessor.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/SmartInstantiationAwareBeanPostProcessor.java @@ -19,6 +19,7 @@ package org.springframework.beans.factory.config; import java.lang.reflect.Constructor; import org.springframework.beans.BeansException; +import org.springframework.lang.Nullable; /** * Extension of the {@link InstantiationAwareBeanPostProcessor} interface, @@ -45,6 +46,7 @@ public interface SmartInstantiationAwareBeanPostProcessor extends InstantiationA * @return the type of the bean, or {@code null} if not predictable * @throws org.springframework.beans.BeansException in case of errors */ + @Nullable default Class predictBeanType(Class beanClass, String beanName) throws BeansException { return null; } @@ -57,6 +59,7 @@ public interface SmartInstantiationAwareBeanPostProcessor extends InstantiationA * @return the candidate constructors, or {@code null} if none specified * @throws org.springframework.beans.BeansException in case of errors */ + @Nullable default Constructor[] determineCandidateConstructors(Class beanClass, String beanName) throws BeansException { diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/TypedStringValue.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/TypedStringValue.java index 0a6f73e350..1454ae8d59 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/TypedStringValue.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/TypedStringValue.java @@ -17,6 +17,7 @@ package org.springframework.beans.factory.config; import org.springframework.beans.BeanMetadataElement; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.ObjectUtils; @@ -153,6 +154,7 @@ public class TypedStringValue implements BeanMetadataElement { * @return the resolved type to convert to * @throws ClassNotFoundException if the type cannot be resolved */ + @Nullable public Class resolveTargetType(ClassLoader classLoader) throws ClassNotFoundException { if (this.targetType == null) { return null; @@ -179,13 +181,14 @@ public class TypedStringValue implements BeanMetadataElement { /** * Set the type name as actually specified for this particular value, if any. */ - public void setSpecifiedTypeName(String specifiedTypeName) { + public void setSpecifiedTypeName(@Nullable String specifiedTypeName) { this.specifiedTypeName = specifiedTypeName; } /** * Return the type name as actually specified for this particular value, if any. */ + @Nullable public String getSpecifiedTypeName() { return this.specifiedTypeName; } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/package-info.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/package-info.java index 81e5ad6668..1bfd372f34 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/package-info.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/package-info.java @@ -1,4 +1,7 @@ /** * SPI interfaces and configuration-related convenience classes for bean factories. */ +@NonNullApi package org.springframework.beans.factory.config; + +import org.springframework.lang.NonNullApi; diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/package-info.java b/spring-beans/src/main/java/org/springframework/beans/factory/package-info.java index 0834baa9e5..10b3a3a3cf 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/package-info.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/package-info.java @@ -9,4 +9,7 @@ * Expert One-On-One J2EE Design and Development * by Rod Johnson (Wrox, 2002). */ +@NonNullApi package org.springframework.beans.factory; + +import org.springframework.lang.NonNullApi; diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/parsing/AliasDefinition.java b/spring-beans/src/main/java/org/springframework/beans/factory/parsing/AliasDefinition.java index 06d037c5d7..e87d3c5ca9 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/parsing/AliasDefinition.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/parsing/AliasDefinition.java @@ -17,6 +17,7 @@ package org.springframework.beans.factory.parsing; import org.springframework.beans.BeanMetadataElement; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -50,7 +51,7 @@ public class AliasDefinition implements BeanMetadataElement { * @param alias the alias registered for the bean * @param source the source object (may be {@code null}) */ - public AliasDefinition(String beanName, String alias, Object source) { + public AliasDefinition(String beanName, String alias, @Nullable Object source) { Assert.notNull(beanName, "Bean name must not be null"); Assert.notNull(alias, "Alias must not be null"); this.beanName = beanName; diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/parsing/BeanComponentDefinition.java b/spring-beans/src/main/java/org/springframework/beans/factory/parsing/BeanComponentDefinition.java index fe309eeb3c..c5b1c54a39 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/parsing/BeanComponentDefinition.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/parsing/BeanComponentDefinition.java @@ -24,6 +24,7 @@ import org.springframework.beans.PropertyValues; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.BeanDefinitionHolder; import org.springframework.beans.factory.config.BeanReference; +import org.springframework.lang.Nullable; /** * ComponentDefinition based on a standard BeanDefinition, exposing the given bean @@ -56,7 +57,7 @@ public class BeanComponentDefinition extends BeanDefinitionHolder implements Com * @param beanName the name of the bean * @param aliases alias names for the bean, or {@code null} if none */ - public BeanComponentDefinition(BeanDefinition beanDefinition, String beanName, String[] aliases) { + public BeanComponentDefinition(BeanDefinition beanDefinition, String beanName, @Nullable String[] aliases) { super(beanDefinition, beanName, aliases); findInnerBeanDefinitionsAndBeanReferences(beanDefinition); } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/parsing/FailFastProblemReporter.java b/spring-beans/src/main/java/org/springframework/beans/factory/parsing/FailFastProblemReporter.java index 859d611f14..dbafd3fddc 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/parsing/FailFastProblemReporter.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/parsing/FailFastProblemReporter.java @@ -19,6 +19,8 @@ package org.springframework.beans.factory.parsing; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.lang.Nullable; + /** * Simple {@link ProblemReporter} implementation that exhibits fail-fast * behavior when errors are encountered. @@ -45,7 +47,7 @@ public class FailFastProblemReporter implements ProblemReporter { * the name of the instance class will be used. * @param logger the {@link Log logger} that is to be used to report warnings */ - public void setLogger(Log logger) { + public void setLogger(@Nullable Log logger) { this.logger = (logger != null ? logger : LogFactory.getLog(getClass())); } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/parsing/ImportDefinition.java b/spring-beans/src/main/java/org/springframework/beans/factory/parsing/ImportDefinition.java index 85eea69610..fdab1473e0 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/parsing/ImportDefinition.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/parsing/ImportDefinition.java @@ -18,6 +18,7 @@ package org.springframework.beans.factory.parsing; import org.springframework.beans.BeanMetadataElement; import org.springframework.core.io.Resource; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -49,7 +50,7 @@ public class ImportDefinition implements BeanMetadataElement { * @param importedResource the location of the imported resource * @param source the source object (may be {@code null}) */ - public ImportDefinition(String importedResource, Object source) { + public ImportDefinition(String importedResource, @Nullable Object source) { this(importedResource, null, source); } @@ -58,7 +59,7 @@ public class ImportDefinition implements BeanMetadataElement { * @param importedResource the location of the imported resource * @param source the source object (may be {@code null}) */ - public ImportDefinition(String importedResource, Resource[] actualResources, Object source) { + public ImportDefinition(String importedResource, Resource[] actualResources, @Nullable Object source) { Assert.notNull(importedResource, "Imported resource must not be null"); this.importedResource = importedResource; this.actualResources = actualResources; diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/parsing/Location.java b/spring-beans/src/main/java/org/springframework/beans/factory/parsing/Location.java index 9ff54665c7..23747a032e 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/parsing/Location.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/parsing/Location.java @@ -17,6 +17,7 @@ package org.springframework.beans.factory.parsing; import org.springframework.core.io.Resource; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -53,7 +54,7 @@ public class Location { * @param source the actual location within the associated resource * (may be {@code null}) */ - public Location(Resource resource, Object source) { + public Location(Resource resource, @Nullable Object source) { Assert.notNull(resource, "Resource must not be null"); this.resource = resource; this.source = source; @@ -73,6 +74,7 @@ public class Location { *

See the {@link Location class level javadoc for this class} for examples * of what the actual type of the returned object may be. */ + @Nullable public Object getSource() { return this.source; } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/parsing/ParseState.java b/spring-beans/src/main/java/org/springframework/beans/factory/parsing/ParseState.java index 2edb93890d..7e3ff72e52 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/parsing/ParseState.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/parsing/ParseState.java @@ -18,6 +18,8 @@ package org.springframework.beans.factory.parsing; import java.util.Stack; +import org.springframework.lang.Nullable; + /** * Simple {@link Stack}-based structure for tracking the logical position during * a parsing process. {@link Entry entries} are added to the stack at @@ -78,6 +80,7 @@ public final class ParseState { * Return the {@link Entry} currently at the top of the {@link Stack} or * {@code null} if the {@link Stack} is empty. */ + @Nullable public Entry peek() { return this.state.empty() ? null : this.state.peek(); } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/parsing/Problem.java b/spring-beans/src/main/java/org/springframework/beans/factory/parsing/Problem.java index c317d5f935..a8150dc2f0 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/parsing/Problem.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/parsing/Problem.java @@ -16,6 +16,7 @@ package org.springframework.beans.factory.parsing; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -66,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, Throwable rootCause) { + public Problem(String message, Location location, ParseState parseState, @Nullable Throwable rootCause) { Assert.notNull(message, "Message must not be null"); Assert.notNull(location, "Location must not be null"); this.message = message; @@ -102,6 +103,7 @@ public class Problem { /** * Get the {@link ParseState} at the time of the error (may be {@code null}). */ + @Nullable public ParseState getParseState() { return this.parseState; } @@ -109,6 +111,7 @@ public class Problem { /** * Get the underlying exception that caused the error (may be {@code null}). */ + @Nullable public Throwable getRootCause() { return this.rootCause; } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/parsing/SourceExtractor.java b/spring-beans/src/main/java/org/springframework/beans/factory/parsing/SourceExtractor.java index ed9248fdf2..a403c5c229 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/parsing/SourceExtractor.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/parsing/SourceExtractor.java @@ -17,6 +17,7 @@ package org.springframework.beans.factory.parsing; import org.springframework.core.io.Resource; +import org.springframework.lang.Nullable; /** * Simple strategy allowing tools to control how source metadata is attached @@ -44,6 +45,7 @@ public interface SourceExtractor { * (may be {@code null}) * @return the source metadata object to store (may be {@code null}) */ - Object extractSource(Object sourceCandidate, Resource definingResource); + @Nullable + Object extractSource(Object sourceCandidate, @Nullable Resource definingResource); } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/parsing/package-info.java b/spring-beans/src/main/java/org/springframework/beans/factory/parsing/package-info.java index eae9057e60..ab87c9bc5d 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/parsing/package-info.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/parsing/package-info.java @@ -1,4 +1,7 @@ /** * Support infrastructure for bean definition parsing. */ +@NonNullApi package org.springframework.beans.factory.parsing; + +import org.springframework.lang.NonNullApi; diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/serviceloader/package-info.java b/spring-beans/src/main/java/org/springframework/beans/factory/serviceloader/package-info.java index 793df3de8b..71ae523912 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/serviceloader/package-info.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/serviceloader/package-info.java @@ -1,4 +1,7 @@ /** * Support package for the Java 6 ServiceLoader facility. */ +@NonNullApi package org.springframework.beans.factory.serviceloader; + +import org.springframework.lang.NonNullApi; diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java index b306901faa..811b914044 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java @@ -77,6 +77,7 @@ import org.springframework.core.NamedThreadLocal; import org.springframework.core.ParameterNameDiscoverer; import org.springframework.core.PriorityOrdered; import org.springframework.core.ResolvableType; +import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.util.ObjectUtils; import org.springframework.util.ReflectionUtils; @@ -175,7 +176,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac * Create a new AbstractAutowireCapableBeanFactory with the given parent. * @param parentBeanFactory parent bean factory, or {@code null} if none */ - public AbstractAutowireCapableBeanFactory(BeanFactory parentBeanFactory) { + public AbstractAutowireCapableBeanFactory(@Nullable BeanFactory parentBeanFactory) { this(); setParentBeanFactory(parentBeanFactory); } @@ -654,6 +655,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac * (also signals that the returned {@code Class} will never be exposed to application code) * @return the type for the bean if determinable, or {@code null} otherwise */ + @Nullable protected Class determineTargetType(String beanName, RootBeanDefinition mbd, Class... typesToMatch) { Class targetType = mbd.getTargetType(); if (targetType == null) { @@ -681,6 +683,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac * @return the type for the bean if determinable, or {@code null} otherwise * @see #createBean */ + @Nullable protected Class getTypeForFactoryMethod(String beanName, RootBeanDefinition mbd, Class... typesToMatch) { ResolvableType cachedReturnType = mbd.factoryMethodReturnType; if (cachedReturnType != null) { @@ -858,6 +861,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac * @param factoryMethodName the name of the factory method * @return the common {@code FactoryBean} object type, or {@code null} if none */ + @Nullable private Class getTypeForFactoryBeanFromMethod(Class beanClass, final String factoryMethodName) { class Holder { Class value = null; } final Holder objectType = new Holder(); @@ -893,6 +897,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac * @param bean the raw bean instance * @return the object to expose as bean reference */ + @Nullable protected Object getEarlyBeanReference(String beanName, RootBeanDefinition mbd, Object bean) { Object exposedObject = bean; if (bean != null && !mbd.isSynthetic() && hasInstantiationAwareBeanPostProcessors()) { @@ -922,6 +927,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac * @return the FactoryBean instance, or {@code null} to indicate * that we couldn't obtain a shortcut FactoryBean instance */ + @Nullable private FactoryBean getSingletonFactoryBeanForTypeCheck(String beanName, RootBeanDefinition mbd) { synchronized (getSingletonMutex()) { BeanWrapper bw = this.factoryBeanInstanceCache.get(beanName); @@ -965,6 +971,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac * @return the FactoryBean instance, or {@code null} to indicate * that we couldn't obtain a shortcut FactoryBean instance */ + @Nullable private FactoryBean getNonSingletonFactoryBeanForTypeCheck(String beanName, RootBeanDefinition mbd) { if (isPrototypeCurrentlyInCreation(beanName)) { return null; @@ -1021,6 +1028,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac * @param mbd the bean definition for the bean * @return the shortcut-determined bean instance, or {@code null} if none */ + @Nullable protected Object resolveBeforeInstantiation(String beanName, RootBeanDefinition mbd) { Object bean = null; if (!Boolean.FALSE.equals(mbd.beforeInstantiationResolved)) { @@ -1050,6 +1058,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac * @return the bean object to use instead of a default instance of the target bean, or {@code null} * @see InstantiationAwareBeanPostProcessor#postProcessBeforeInstantiation */ + @Nullable protected Object applyBeanPostProcessorsBeforeInstantiation(Class beanClass, String beanName) { for (BeanPostProcessor bp : getBeanPostProcessors()) { if (bp instanceof InstantiationAwareBeanPostProcessor) { @@ -1181,6 +1190,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac * @throws org.springframework.beans.BeansException in case of errors * @see org.springframework.beans.factory.config.SmartInstantiationAwareBeanPostProcessor#determineCandidateConstructors */ + @Nullable protected Constructor[] determineConstructorsFromBeanPostProcessors(Class beanClass, String beanName) throws BeansException { @@ -1241,7 +1251,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac * @see #getBean(String, Object[]) */ protected BeanWrapper instantiateUsingFactoryMethod( - String beanName, RootBeanDefinition mbd, Object[] explicitArgs) { + String beanName, RootBeanDefinition mbd, @Nullable Object[] explicitArgs) { return new ConstructorResolver(this).instantiateUsingFactoryMethod(beanName, mbd, explicitArgs); } @@ -1261,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, Object[] explicitArgs) { + String beanName, RootBeanDefinition mbd, Constructor[] ctors, @Nullable Object[] explicitArgs) { return new ConstructorResolver(this).autowireConstructor(beanName, mbd, ctors, explicitArgs); } @@ -1674,7 +1684,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac * @see #invokeInitMethods * @see #applyBeanPostProcessorsAfterInitialization */ - protected Object initializeBean(final String beanName, final Object bean, RootBeanDefinition mbd) { + protected Object initializeBean(final String beanName, final Object bean, @Nullable RootBeanDefinition mbd) { if (System.getSecurityManager() != null) { AccessController.doPrivileged(new PrivilegedAction() { @Override @@ -1734,7 +1744,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac * @throws Throwable if thrown by init methods or by the invocation process * @see #invokeCustomInitMethod */ - protected void invokeInitMethods(String beanName, final Object bean, RootBeanDefinition mbd) + protected void invokeInitMethods(String beanName, final Object bean, @Nullable RootBeanDefinition mbd) throws Throwable { boolean isInitializingBean = (bean instanceof InitializingBean); diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanDefinition.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanDefinition.java index 7b21fcb3ec..5cdab4336d 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanDefinition.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanDefinition.java @@ -31,6 +31,7 @@ import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.ConstructorArgumentValues; import org.springframework.core.io.DescriptiveResource; import org.springframework.core.io.Resource; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.ObjectUtils; @@ -370,6 +371,7 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess * @throws IllegalStateException if the bean definition does not define a bean class, * or a specified bean class name has not been resolved into an actual Class */ + @Nullable public Class getBeanClass() throws IllegalStateException { Object beanClassObject = this.beanClass; if (beanClassObject == null) { @@ -674,6 +676,7 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess * Return a callback for creating an instance of the bean, if any. * @since 5.0 */ + @Nullable public Supplier getInstanceSupplier() { return this.instanceSupplier; } @@ -821,6 +824,7 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess /** * Return the name of the initializer method. */ + @Nullable public String getInitMethodName() { return this.initMethodName; } @@ -853,6 +857,7 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess /** * Return the name of the destroy method. */ + @Nullable public String getDestroyMethodName() { return this.destroyMethodName; } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanDefinitionReader.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanDefinitionReader.java index bca9efeba9..a935bdbe26 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanDefinitionReader.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanDefinitionReader.java @@ -30,6 +30,7 @@ import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceLoader; import org.springframework.core.io.support.PathMatchingResourcePatternResolver; import org.springframework.core.io.support.ResourcePatternResolver; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -119,7 +120,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; } @@ -203,7 +204,7 @@ public abstract class AbstractBeanDefinitionReader implements EnvironmentCapable * @see #loadBeanDefinitions(org.springframework.core.io.Resource) * @see #loadBeanDefinitions(org.springframework.core.io.Resource[]) */ - public int loadBeanDefinitions(String location, Set actualResources) throws BeanDefinitionStoreException { + public int loadBeanDefinitions(String location, @Nullable Set actualResources) throws BeanDefinitionStoreException { ResourceLoader resourceLoader = getResourceLoader(); if (resourceLoader == null) { throw new BeanDefinitionStoreException( diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java index e4ab8b727f..3e43d826ff 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java @@ -71,6 +71,7 @@ import org.springframework.core.DecoratingClassLoader; import org.springframework.core.NamedThreadLocal; import org.springframework.core.ResolvableType; import org.springframework.core.convert.ConversionService; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.ObjectUtils; @@ -179,7 +180,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp * @param parentBeanFactory parent bean factory, or {@code null} if none * @see #getBean */ - public AbstractBeanFactory(BeanFactory parentBeanFactory) { + public AbstractBeanFactory(@Nullable BeanFactory parentBeanFactory) { this.parentBeanFactory = parentBeanFactory; } @@ -787,6 +788,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp * Return the custom TypeConverter to use, if any. * @return the custom TypeConverter, or {@code null} if none specified */ + @Nullable protected TypeConverter getCustomTypeConverter() { return this.typeConverter; } @@ -1228,7 +1230,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp * @throws BeanDefinitionStoreException in case of an invalid bean definition */ protected RootBeanDefinition getMergedBeanDefinition( - String beanName, BeanDefinition bd, BeanDefinition containingBd) + String beanName, BeanDefinition bd, @Nullable BeanDefinition containingBd) throws BeanDefinitionStoreException { synchronized (this.mergedBeanDefinitions) { @@ -1310,7 +1312,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp * @param args the arguments for bean creation, if any * @throws BeanDefinitionStoreException in case of validation failure */ - protected void checkMergedBeanDefinition(RootBeanDefinition mbd, String beanName, Object[] args) + protected void checkMergedBeanDefinition(RootBeanDefinition mbd, String beanName, @Nullable Object[] args) throws BeanDefinitionStoreException { if (mbd.isAbstract()) { @@ -1355,6 +1357,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp * @return the resolved bean class (or {@code null} if none) * @throws CannotLoadBeanClassException if we failed to load the class */ + @Nullable protected Class resolveBeanClass(final RootBeanDefinition mbd, String beanName, final Class... typesToMatch) throws CannotLoadBeanClassException { try { @@ -1460,6 +1463,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp * (also signals that the returned {@code Class} will never be exposed to application code) * @return the type of the bean, or {@code null} if not predictable */ + @Nullable protected Class predictBeanType(String beanName, RootBeanDefinition mbd, Class... typesToMatch) { Class targetType = mbd.getTargetType(); if (targetType != null) { @@ -1496,6 +1500,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp * @see org.springframework.beans.factory.FactoryBean#getObjectType() * @see #getBean(String) */ + @Nullable protected Class getTypeForFactoryBean(String beanName, RootBeanDefinition mbd) { if (!mbd.isSingleton()) { return null; diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/AutowireCandidateResolver.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/AutowireCandidateResolver.java index a1e2eaf9f1..37ef03304d 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/AutowireCandidateResolver.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/AutowireCandidateResolver.java @@ -18,6 +18,7 @@ package org.springframework.beans.factory.support; import org.springframework.beans.factory.config.BeanDefinitionHolder; import org.springframework.beans.factory.config.DependencyDescriptor; +import org.springframework.lang.Nullable; /** * Strategy interface for determining whether a specific bean definition @@ -64,6 +65,7 @@ public interface AutowireCandidateResolver { * or {@code null} if none found * @since 3.0 */ + @Nullable default Object getSuggestedValue(DependencyDescriptor descriptor) { return null; } @@ -78,6 +80,7 @@ public interface AutowireCandidateResolver { * or {@code null} if straight resolution is to be performed * @since 4.0 */ + @Nullable default Object getLazyResolutionProxyIfNecessary(DependencyDescriptor descriptor, String beanName) { return null; } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionReader.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionReader.java index bd8b8f51b5..e14a7dc483 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionReader.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionReader.java @@ -19,6 +19,7 @@ package org.springframework.beans.factory.support; import org.springframework.beans.factory.BeanDefinitionStoreException; import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceLoader; +import org.springframework.lang.Nullable; /** * Simple interface for bean definition readers. @@ -70,6 +71,7 @@ public interface BeanDefinitionReader { * but rather to just register bean definitions with class names, * with the corresponding Classes to be resolved later (or never). */ + @Nullable ClassLoader getBeanClassLoader(); /** diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionReaderUtils.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionReaderUtils.java index 8a745dab2c..1098273a3d 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionReaderUtils.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionReaderUtils.java @@ -20,6 +20,7 @@ import org.springframework.beans.factory.BeanDefinitionStoreException; import org.springframework.beans.factory.BeanFactoryUtils; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.BeanDefinitionHolder; +import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; @@ -54,7 +55,7 @@ public class BeanDefinitionReaderUtils { * @throws ClassNotFoundException if the bean class could not be loaded */ public static AbstractBeanDefinition createBeanDefinition( - String parentName, String className, ClassLoader classLoader) throws ClassNotFoundException { + @Nullable String parentName, @Nullable String className, @Nullable ClassLoader classLoader) throws ClassNotFoundException { GenericBeanDefinition bd = new GenericBeanDefinition(); bd.setParentName(parentName); diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionValueResolver.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionValueResolver.java index 29acd9c9d8..7d60ad437b 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionValueResolver.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionValueResolver.java @@ -37,6 +37,7 @@ import org.springframework.beans.factory.config.BeanDefinitionHolder; import org.springframework.beans.factory.config.RuntimeBeanNameReference; import org.springframework.beans.factory.config.RuntimeBeanReference; import org.springframework.beans.factory.config.TypedStringValue; +import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; @@ -100,7 +101,7 @@ class BeanDefinitionValueResolver { * @param value the value object to resolve * @return the resolved object */ - public Object resolveValueIfNecessary(Object argName, Object value) { + public Object resolveValueIfNecessary(Object argName, @Nullable Object value) { // We must check each value to see whether it requires a runtime reference // to another bean to be resolved. if (value instanceof RuntimeBeanReference) { @@ -262,6 +263,7 @@ class BeanDefinitionValueResolver { * @throws ClassNotFoundException if the specified type cannot be resolved * @see TypedStringValue#resolveTargetType */ + @Nullable protected Class resolveTargetType(TypedStringValue value) throws ClassNotFoundException { if (value.hasTargetType()) { return value.getTargetType(); diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/CglibSubclassingInstantiationStrategy.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/CglibSubclassingInstantiationStrategy.java index cbb9d2f153..0c140d4793 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/CglibSubclassingInstantiationStrategy.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/CglibSubclassingInstantiationStrategy.java @@ -36,6 +36,7 @@ import org.springframework.cglib.proxy.Factory; import org.springframework.cglib.proxy.MethodInterceptor; import org.springframework.cglib.proxy.MethodProxy; import org.springframework.cglib.proxy.NoOp; +import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; /** @@ -111,7 +112,7 @@ public class CglibSubclassingInstantiationStrategy extends SimpleInstantiationSt * Ignored if the {@code ctor} parameter is {@code null}. * @return new instance of the dynamically generated subclass */ - public Object instantiate(Constructor ctor, Object... args) { + public Object instantiate(@Nullable Constructor ctor, Object... args) { Class subclass = createEnhancedSubclass(this.beanDefinition); Object instance; if (ctor == null) { diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/ConstructorResolver.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/ConstructorResolver.java index 1fb4c1e6bd..399e437c95 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/ConstructorResolver.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/ConstructorResolver.java @@ -49,6 +49,7 @@ import org.springframework.core.GenericTypeResolver; import org.springframework.core.MethodParameter; import org.springframework.core.NamedThreadLocal; import org.springframework.core.ParameterNameDiscoverer; +import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.util.MethodInvoker; import org.springframework.util.ObjectUtils; @@ -100,7 +101,7 @@ class ConstructorResolver { * @return a BeanWrapper for the new instance */ public BeanWrapper autowireConstructor(final String beanName, final RootBeanDefinition mbd, - Constructor[] chosenCtors, final Object[] explicitArgs) { + @Nullable Constructor[] chosenCtors, @Nullable final Object[] explicitArgs) { BeanWrapperImpl bw = new BeanWrapperImpl(); this.beanFactory.initBeanWrapper(bw); @@ -353,8 +354,9 @@ class ConstructorResolver { * method, or {@code null} if none (-> use constructor argument values from bean definition) * @return a BeanWrapper for the new instance */ + @Nullable public BeanWrapper instantiateUsingFactoryMethod( - final String beanName, final RootBeanDefinition mbd, final Object[] explicitArgs) { + final String beanName, final RootBeanDefinition mbd, @Nullable final Object[] explicitArgs) { BeanWrapperImpl bw = new BeanWrapperImpl(); this.beanFactory.initBeanWrapper(bw); @@ -924,6 +926,7 @@ class ConstructorResolver { */ private static class ConstructorPropertiesChecker { + @Nullable public static String[] evaluate(Constructor candidate, int paramCount) { ConstructorProperties cp = candidate.getAnnotation(ConstructorProperties.class); if (cp != null) { diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java index e5f7465fc7..d0f14b96df 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java @@ -41,6 +41,7 @@ import java.util.Map; import java.util.Optional; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; + import javax.inject.Provider; import org.springframework.beans.BeanUtils; @@ -72,6 +73,7 @@ import org.springframework.beans.factory.config.NamedBeanHolder; import org.springframework.core.OrderComparator; import org.springframework.core.ResolvableType; import org.springframework.core.annotation.AnnotationUtils; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.CompositeIterator; @@ -269,6 +271,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto * Return the dependency comparator for this BeanFactory (may be {@code null}. * @since 4.0 */ + @Nullable public Comparator getDependencyComparator() { return this.dependencyComparator; } @@ -987,6 +990,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto } @SuppressWarnings("unchecked") + @Nullable private NamedBeanHolder resolveNamedBean(Class requiredType, Object... args) throws BeansException { Assert.notNull(requiredType, "Required type must not be null"); String[] candidateNames = getBeanNamesForType(requiredType); @@ -1059,6 +1063,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto } } + @Nullable public Object doResolveDependency(DependencyDescriptor descriptor, String beanName, Set autowiredBeanNames, TypeConverter typeConverter) throws BeansException { @@ -1315,6 +1320,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto * @param descriptor the target dependency to match against * @return the name of the autowire candidate, or {@code null} if none found */ + @Nullable protected String determineAutowireCandidate(Map candidates, DependencyDescriptor descriptor) { Class requiredType = descriptor.getDependencyType(); String primaryCandidate = determinePrimaryCandidate(candidates, requiredType); @@ -1345,6 +1351,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto * @return the name of the primary candidate, or {@code null} if none found * @see #isPrimary(String, Object) */ + @Nullable protected String determinePrimaryCandidate(Map candidates, Class requiredType) { String primaryBeanName = null; for (Map.Entry entry : candidates.entrySet()) { @@ -1382,6 +1389,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto * or {@code null} if none found * @see #getPriority(Object) */ + @Nullable protected String determineHighestPriorityCandidate(Map candidates, Class requiredType) { String highestPriorityBeanName = null; Integer highestPriority = null; @@ -1438,6 +1446,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto * @param beanInstance the bean instance to check (can be {@code null}) * @return the priority assigned to that bean or {@code null} if none is set */ + @Nullable protected Integer getPriority(Object beanInstance) { Comparator comparator = getDependencyComparator(); if (comparator instanceof OrderComparator) { @@ -1727,6 +1736,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto return sources.toArray(new Object[sources.size()]); } + @Nullable private RootBeanDefinition getRootBeanDefinition(String beanName) { if (beanName != null && containsBeanDefinition(beanName)) { BeanDefinition bd = getMergedBeanDefinition(beanName); diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultSingletonBeanRegistry.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultSingletonBeanRegistry.java index 077c7804ee..4ac4c91a1a 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultSingletonBeanRegistry.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultSingletonBeanRegistry.java @@ -36,6 +36,7 @@ import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.ObjectFactory; import org.springframework.beans.factory.config.SingletonBeanRegistry; import org.springframework.core.SimpleAliasRegistry; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -181,6 +182,7 @@ public class DefaultSingletonBeanRegistry extends SimpleAliasRegistry implements * @param allowEarlyReference whether early references should be created or not * @return the registered singleton object, or {@code null} if none found */ + @Nullable protected Object getSingleton(String beanName, boolean allowEarlyReference) { Object singletonObject = this.singletonObjects.get(beanName); if (singletonObject == null && isSingletonCurrentlyInCreation(beanName)) { diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/DisposableBeanAdapter.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/DisposableBeanAdapter.java index 9f4e33d7f3..5aa6a59164 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/DisposableBeanAdapter.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/DisposableBeanAdapter.java @@ -34,6 +34,7 @@ import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.beans.factory.config.DestructionAwareBeanPostProcessor; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.CollectionUtils; @@ -175,6 +176,7 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable { *

Also processes the {@link java.io.Closeable} and {@link java.lang.AutoCloseable} * interfaces, reflectively calling the "close" method on implementing beans as well. */ + @Nullable private String inferDestroyMethodIfNecessary(Object bean, RootBeanDefinition beanDefinition) { String destroyMethodName = beanDefinition.getDestroyMethodName(); if (AbstractBeanDefinition.INFER_METHOD.equals(destroyMethodName) || diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/FactoryBeanRegistrySupport.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/FactoryBeanRegistrySupport.java index e83bec3633..42a1582936 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/FactoryBeanRegistrySupport.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/FactoryBeanRegistrySupport.java @@ -29,6 +29,7 @@ import org.springframework.beans.factory.BeanCreationException; import org.springframework.beans.factory.BeanCurrentlyInCreationException; import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.FactoryBeanNotInitializedException; +import org.springframework.lang.Nullable; /** * Support base class for singleton registries which need to handle @@ -52,6 +53,7 @@ public abstract class FactoryBeanRegistrySupport extends DefaultSingletonBeanReg * @return the FactoryBean's object type, * or {@code null} if the type cannot be determined yet */ + @Nullable protected Class getTypeForFactoryBean(final FactoryBean factoryBean) { try { if (System.getSecurityManager() != null) { @@ -81,6 +83,7 @@ public abstract class FactoryBeanRegistrySupport extends DefaultSingletonBeanReg * @return the object obtained from the FactoryBean, * or {@code null} if not available */ + @Nullable protected Object getCachedObjectForFactoryBean(String beanName) { Object object = this.factoryBeanObjectCache.get(beanName); return (object != NULL_OBJECT ? object : null); diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/GenericTypeAwareAutowireCandidateResolver.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/GenericTypeAwareAutowireCandidateResolver.java index 7ffbed3e0e..2052734096 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/GenericTypeAwareAutowireCandidateResolver.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/GenericTypeAwareAutowireCandidateResolver.java @@ -26,6 +26,7 @@ import org.springframework.beans.factory.config.BeanDefinitionHolder; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.config.DependencyDescriptor; import org.springframework.core.ResolvableType; +import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; /** @@ -131,6 +132,7 @@ public class GenericTypeAwareAutowireCandidateResolver extends SimpleAutowireCan return dependencyType.isAssignableFrom(targetType); } + @Nullable protected RootBeanDefinition getResolvedDecoratedDefinition(RootBeanDefinition rbd) { BeanDefinitionHolder decDef = rbd.getDecoratedDefinition(); if (decDef != null && this.beanFactory instanceof ConfigurableListableBeanFactory) { @@ -145,6 +147,7 @@ public class GenericTypeAwareAutowireCandidateResolver extends SimpleAutowireCan return null; } + @Nullable protected ResolvableType getReturnTypeForFactoryMethod(RootBeanDefinition rbd, DependencyDescriptor descriptor) { // Should typically be set for any kind of factory method, since the BeanFactory // pre-resolves them before reaching out to the AutowireCandidateResolver... diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/InstantiationStrategy.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/InstantiationStrategy.java index 6aec7e8aa3..f4a84638ae 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/InstantiationStrategy.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/InstantiationStrategy.java @@ -21,6 +21,7 @@ import java.lang.reflect.Method; import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanFactory; +import org.springframework.lang.Nullable; /** * Interface responsible for creating instances corresponding to a root bean definition. @@ -44,7 +45,7 @@ public interface InstantiationStrategy { * @return a bean instance for this bean definition * @throws BeansException if the instantiation attempt failed */ - Object instantiate(RootBeanDefinition bd, String beanName, BeanFactory owner) + Object instantiate(RootBeanDefinition bd, @Nullable String beanName, BeanFactory owner) throws BeansException; /** @@ -60,7 +61,7 @@ public interface InstantiationStrategy { * @return a bean instance for this bean definition * @throws BeansException if the instantiation attempt failed */ - Object instantiate(RootBeanDefinition bd, String beanName, BeanFactory owner, + Object instantiate(RootBeanDefinition bd, @Nullable String beanName, BeanFactory owner, Constructor ctor, Object... args) throws BeansException; /** @@ -78,7 +79,7 @@ public interface InstantiationStrategy { * @return a bean instance for this bean definition * @throws BeansException if the instantiation attempt failed */ - Object instantiate(RootBeanDefinition bd, String beanName, BeanFactory owner, - Object factoryBean, Method factoryMethod, Object... args) throws BeansException; + Object instantiate(RootBeanDefinition bd, @Nullable String beanName, BeanFactory owner, + @Nullable Object factoryBean, Method factoryMethod, Object... args) throws BeansException; } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/LookupOverride.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/LookupOverride.java index 1a92d8bc40..6fcc4e3f3b 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/LookupOverride.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/LookupOverride.java @@ -19,6 +19,7 @@ package org.springframework.beans.factory.support; import java.lang.reflect.Method; import java.lang.reflect.Modifier; +import org.springframework.lang.Nullable; import org.springframework.util.ObjectUtils; /** @@ -43,7 +44,7 @@ public class LookupOverride extends MethodOverride { * @param beanName the name of the bean in the current {@code BeanFactory} * that the overridden method should return (may be {@code null}) */ - public LookupOverride(String methodName, String beanName) { + public LookupOverride(String methodName, @Nullable String beanName) { super(methodName); this.beanName = beanName; } @@ -54,7 +55,7 @@ public class LookupOverride extends MethodOverride { * @param beanName the name of the bean in the current {@code BeanFactory} * that the overridden method should return (may be {@code null}) */ - public LookupOverride(Method method, String beanName) { + public LookupOverride(Method method, @Nullable String beanName) { super(method.getName()); this.method = method; this.beanName = beanName; diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/MethodOverrides.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/MethodOverrides.java index 11b98753e9..2d52488ad4 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/MethodOverrides.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/MethodOverrides.java @@ -21,6 +21,8 @@ import java.util.Collections; import java.util.LinkedHashSet; import java.util.Set; +import org.springframework.lang.Nullable; + /** * Set of method overrides, determining which, if any, methods on a * managed object the Spring IoC container will override at runtime. @@ -95,6 +97,7 @@ public class MethodOverrides { * @param method method to check for overrides for * @return the method override, or {@code null} if none */ + @Nullable public MethodOverride getOverride(Method method) { if (!this.modified) { return null; diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/PropertiesBeanDefinitionReader.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/PropertiesBeanDefinitionReader.java index 8797b54afd..d48f80dae4 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/PropertiesBeanDefinitionReader.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/PropertiesBeanDefinitionReader.java @@ -34,6 +34,7 @@ import org.springframework.beans.factory.config.ConstructorArgumentValues; import org.springframework.beans.factory.config.RuntimeBeanReference; import org.springframework.core.io.Resource; import org.springframework.core.io.support.EncodedResource; +import org.springframework.lang.Nullable; import org.springframework.util.DefaultPropertiesPersister; import org.springframework.util.PropertiesPersister; import org.springframework.util.StringUtils; @@ -217,7 +218,7 @@ public class PropertiesBeanDefinitionReader extends AbstractBeanDefinitionReader * @return the number of bean definitions found * @throws BeanDefinitionStoreException in case of loading or parsing errors */ - public int loadBeanDefinitions(Resource resource, String prefix) throws BeanDefinitionStoreException { + public int loadBeanDefinitions(Resource resource, @Nullable String prefix) throws BeanDefinitionStoreException { return loadBeanDefinitions(new EncodedResource(resource), prefix); } @@ -241,7 +242,7 @@ public class PropertiesBeanDefinitionReader extends AbstractBeanDefinitionReader * @return the number of bean definitions found * @throws BeanDefinitionStoreException in case of loading or parsing errors */ - public int loadBeanDefinitions(EncodedResource encodedResource, String prefix) + public int loadBeanDefinitions(EncodedResource encodedResource, @Nullable String prefix) throws BeanDefinitionStoreException { Properties props = new Properties(); @@ -287,7 +288,7 @@ public class PropertiesBeanDefinitionReader extends AbstractBeanDefinitionReader * @return the number of bean definitions found * @throws BeanDefinitionStoreException in case of loading or parsing errors */ - public int registerBeanDefinitions(ResourceBundle rb, String prefix) throws BeanDefinitionStoreException { + public int registerBeanDefinitions(ResourceBundle rb, @Nullable String prefix) throws BeanDefinitionStoreException { // Simply create a map and call overloaded method. Map map = new HashMap<>(); Enumeration keys = rb.getKeys(); @@ -324,7 +325,7 @@ public class PropertiesBeanDefinitionReader extends AbstractBeanDefinitionReader * @return the number of bean definitions found * @throws BeansException in case of loading or parsing errors */ - public int registerBeanDefinitions(Map map, String prefix) throws BeansException { + public int registerBeanDefinitions(Map map, @Nullable String prefix) throws BeansException { return registerBeanDefinitions(map, prefix, "Map " + map); } @@ -342,7 +343,7 @@ public class PropertiesBeanDefinitionReader extends AbstractBeanDefinitionReader * @throws BeansException in case of loading or parsing errors * @see #registerBeanDefinitions(Map, String) */ - public int registerBeanDefinitions(Map map, String prefix, String resourceDescription) + public int registerBeanDefinitions(Map map, @Nullable String prefix, String resourceDescription) throws BeansException { if (prefix == null) { diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/RootBeanDefinition.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/RootBeanDefinition.java index 31ab2a0866..32704c2cc7 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/RootBeanDefinition.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/RootBeanDefinition.java @@ -29,6 +29,7 @@ import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.BeanDefinitionHolder; import org.springframework.beans.factory.config.ConstructorArgumentValues; import org.springframework.core.ResolvableType; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -251,6 +252,7 @@ public class RootBeanDefinition extends AbstractBeanDefinition { /** * Return the target definition that is being decorated by this bean definition, if any. */ + @Nullable public BeanDefinitionHolder getDecoratedDefinition() { return this.decoratedDefinition; } @@ -271,6 +273,7 @@ public class RootBeanDefinition extends AbstractBeanDefinition { * Otherwise, the factory method and target class will be checked. * @since 4.3.3 */ + @Nullable public AnnotatedElement getQualifiedElement() { return this.qualifiedElement; } @@ -323,6 +326,7 @@ public class RootBeanDefinition extends AbstractBeanDefinition { * Return the resolved factory method as a Java Method object, if available. * @return the factory method, or {@code null} if not found or not resolved yet */ + @Nullable public Method getResolvedFactoryMethod() { synchronized (this.constructorArgumentLock) { Executable candidate = this.resolvedConstructorOrFactoryMethod; diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/SimpleInstantiationStrategy.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/SimpleInstantiationStrategy.java index 59fbdaac64..7393fd5aa5 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/SimpleInstantiationStrategy.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/SimpleInstantiationStrategy.java @@ -27,6 +27,7 @@ import org.springframework.beans.BeanInstantiationException; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.lang.Nullable; import org.springframework.util.ReflectionUtils; import org.springframework.util.StringUtils; @@ -50,6 +51,7 @@ public class SimpleInstantiationStrategy implements InstantiationStrategy { *

Allows factory method implementations to determine whether the current * caller is the container itself as opposed to user code. */ + @Nullable public static Method getCurrentlyInvokedFactoryMethod() { return currentlyInvokedFactoryMethod.get(); } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/SimpleSecurityContextProvider.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/SimpleSecurityContextProvider.java index 15aed4c50d..8568a321b1 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/SimpleSecurityContextProvider.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/SimpleSecurityContextProvider.java @@ -19,6 +19,8 @@ package org.springframework.beans.factory.support; import java.security.AccessControlContext; import java.security.AccessController; +import org.springframework.lang.Nullable; + /** * Simple {@link SecurityContextProvider} implementation. * @@ -46,7 +48,7 @@ public class SimpleSecurityContextProvider implements SecurityContextProvider { * @param acc access control context (can be {@code null}) * @see AccessController#getContext() */ - public SimpleSecurityContextProvider(AccessControlContext acc) { + public SimpleSecurityContextProvider(@Nullable AccessControlContext acc) { this.acc = acc; } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/package-info.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/package-info.java index 2f90e25600..df8d1de0ee 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/package-info.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/package-info.java @@ -2,4 +2,7 @@ * Classes supporting the {@code org.springframework.beans.factory} package. * Contains abstract base classes for {@code BeanFactory} implementations. */ +@NonNullApi package org.springframework.beans.factory.support; + +import org.springframework.lang.NonNullApi; diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/wiring/BeanConfigurerSupport.java b/spring-beans/src/main/java/org/springframework/beans/factory/wiring/BeanConfigurerSupport.java index ccfd90f96a..a1e4a9f422 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/wiring/BeanConfigurerSupport.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/wiring/BeanConfigurerSupport.java @@ -26,6 +26,7 @@ import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; @@ -89,6 +90,7 @@ public class BeanConfigurerSupport implements BeanFactoryAware, InitializingBean *

The default implementation builds a {@link ClassNameBeanWiringInfoResolver}. * @return the default BeanWiringInfoResolver (never {@code null}) */ + @Nullable protected BeanWiringInfoResolver createDefaultBeanWiringInfoResolver() { return new ClassNameBeanWiringInfoResolver(); } @@ -118,7 +120,7 @@ public class BeanConfigurerSupport implements BeanFactoryAware, InitializingBean * Typically called by an aspect, for all bean instances matched by a pointcut. * @param beanInstance the bean instance to configure (must not be {@code null}) */ - public void configureBean(Object beanInstance) { + public void configureBean(@Nullable Object beanInstance) { if (this.beanFactory == null) { if (logger.isDebugEnabled()) { logger.debug("BeanFactory has not been set on " + ClassUtils.getShortName(getClass()) + ": " + diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/wiring/BeanWiringInfo.java b/spring-beans/src/main/java/org/springframework/beans/factory/wiring/BeanWiringInfo.java index 67f32d5d2c..eaeafb220e 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/wiring/BeanWiringInfo.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/wiring/BeanWiringInfo.java @@ -17,6 +17,7 @@ package org.springframework.beans.factory.wiring; import org.springframework.beans.factory.config.AutowireCapableBeanFactory; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -118,6 +119,7 @@ public class BeanWiringInfo { /** * Return the specific bean name that this BeanWiringInfo points to, if any. */ + @Nullable public String getBeanName() { return this.beanName; } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/wiring/BeanWiringInfoResolver.java b/spring-beans/src/main/java/org/springframework/beans/factory/wiring/BeanWiringInfoResolver.java index c306cb70bb..97b279c355 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/wiring/BeanWiringInfoResolver.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/wiring/BeanWiringInfoResolver.java @@ -16,6 +16,8 @@ package org.springframework.beans.factory.wiring; +import org.springframework.lang.Nullable; + /** * Strategy interface to be implemented by objects than can resolve bean name * information, given a newly instantiated bean object. Invocations to the @@ -39,6 +41,7 @@ public interface BeanWiringInfoResolver { * @param beanInstance the bean instance to resolve info for * @return the BeanWiringInfo, or {@code null} if not found */ + @Nullable BeanWiringInfo resolveWiringInfo(Object beanInstance); } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/wiring/package-info.java b/spring-beans/src/main/java/org/springframework/beans/factory/wiring/package-info.java index 5f5c9d6209..eac2388aec 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/wiring/package-info.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/wiring/package-info.java @@ -2,4 +2,7 @@ * Mechanism to determine bean wiring metadata from a bean instance. * Foundation for aspect-driven bean configuration. */ +@NonNullApi package org.springframework.beans.factory.wiring; + +import org.springframework.lang.NonNullApi; diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/xml/AbstractSingleBeanDefinitionParser.java b/spring-beans/src/main/java/org/springframework/beans/factory/xml/AbstractSingleBeanDefinitionParser.java index ec5d368740..1310fc513b 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/xml/AbstractSingleBeanDefinitionParser.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/xml/AbstractSingleBeanDefinitionParser.java @@ -20,6 +20,7 @@ import org.w3c.dom.Element; import org.springframework.beans.factory.support.AbstractBeanDefinition; import org.springframework.beans.factory.support.BeanDefinitionBuilder; +import org.springframework.lang.Nullable; /** * Base class for those {@link BeanDefinitionParser} implementations that @@ -95,6 +96,7 @@ public abstract class AbstractSingleBeanDefinitionParser extends AbstractBeanDef * @return the name of the parent bean for the currently parsed bean, * or {@code null} if none */ + @Nullable protected String getParentName(Element element) { return null; } @@ -111,6 +113,7 @@ public abstract class AbstractSingleBeanDefinitionParser extends AbstractBeanDef * the supplied {@code Element}, or {@code null} if none * @see #getBeanClassName */ + @Nullable protected Class getBeanClass(Element element) { return null; } @@ -122,6 +125,7 @@ public abstract class AbstractSingleBeanDefinitionParser extends AbstractBeanDef * the supplied {@code Element}, or {@code null} if none * @see #getBeanClass */ + @Nullable protected String getBeanClassName(Element element) { return null; } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/xml/BeanDefinitionParser.java b/spring-beans/src/main/java/org/springframework/beans/factory/xml/BeanDefinitionParser.java index 2c92ecd477..80379c57bf 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/xml/BeanDefinitionParser.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/xml/BeanDefinitionParser.java @@ -19,6 +19,7 @@ package org.springframework.beans.factory.xml; import org.w3c.dom.Element; import org.springframework.beans.factory.config.BeanDefinition; +import org.springframework.lang.Nullable; /** * Interface used by the {@link DefaultBeanDefinitionDocumentReader} to handle custom, @@ -51,6 +52,7 @@ public interface BeanDefinitionParser { * provides access to a {@link org.springframework.beans.factory.support.BeanDefinitionRegistry} * @return the primary {@link BeanDefinition} */ + @Nullable BeanDefinition parse(Element element, ParserContext parserContext); } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/xml/BeanDefinitionParserDelegate.java b/spring-beans/src/main/java/org/springframework/beans/factory/xml/BeanDefinitionParserDelegate.java index 6d7b210e62..1b8bd0b052 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/xml/BeanDefinitionParserDelegate.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/xml/BeanDefinitionParserDelegate.java @@ -58,6 +58,7 @@ import org.springframework.beans.factory.support.ManagedProperties; import org.springframework.beans.factory.support.ManagedSet; import org.springframework.beans.factory.support.MethodOverrides; import org.springframework.beans.factory.support.ReplaceOverride; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.CollectionUtils; @@ -322,7 +323,7 @@ public class BeanDefinitionParserDelegate { * @param parentDefaults the parent BeanDefinitionParserDelegate (if any) defaults to fall back to * @param root the root element of the current bean definition document (or nested beans element) */ - protected void populateDefaults(DocumentDefaultsDefinition defaults, DocumentDefaultsDefinition parentDefaults, Element root) { + protected void populateDefaults(DocumentDefaultsDefinition defaults, @Nullable DocumentDefaultsDefinition parentDefaults, Element root) { String lazyInit = root.getAttribute(DEFAULT_LAZY_INIT_ATTRIBUTE); if (DEFAULT_VALUE.equals(lazyInit)) { // Potentially inherited from outer sections, otherwise falling back to false. @@ -372,6 +373,7 @@ public class BeanDefinitionParserDelegate { * Return the defaults definition object, or {@code null} if the * defaults have been initialized yet. */ + @Nullable public DocumentDefaultsDefinition getDefaults() { return this.defaults; } @@ -404,6 +406,7 @@ public class BeanDefinitionParserDelegate { * if there were errors during parse. Errors are reported to the * {@link org.springframework.beans.factory.parsing.ProblemReporter}. */ + @Nullable public BeanDefinitionHolder parseBeanDefinitionElement(Element ele) { return parseBeanDefinitionElement(ele, null); } @@ -413,6 +416,7 @@ public class BeanDefinitionParserDelegate { * if there were errors during parse. Errors are reported to the * {@link org.springframework.beans.factory.parsing.ProblemReporter}. */ + @Nullable public BeanDefinitionHolder parseBeanDefinitionElement(Element ele, BeanDefinition containingBean) { String id = ele.getAttribute(ID_ATTRIBUTE); String nameAttr = ele.getAttribute(NAME_ATTRIBUTE); @@ -498,6 +502,7 @@ public class BeanDefinitionParserDelegate { * Parse the bean definition itself, without regard to name or aliases. May return * {@code null} if problems occurred during the parsing of the bean definition. */ + @Nullable public AbstractBeanDefinition parseBeanDefinitionElement( Element ele, String beanName, BeanDefinition containingBean) { @@ -901,6 +906,7 @@ public class BeanDefinitionParserDelegate { * Get the value of a property element. May be a list etc. * Also used for constructor arguments, "propertyName" being null in this case. */ + @Nullable public Object parsePropertyValue(Element ele, BeanDefinition bd, String propertyName) { String elementName = (propertyName != null) ? " element for property '" + propertyName + "'" : @@ -966,6 +972,7 @@ public class BeanDefinitionParserDelegate { * @param defaultValueType the default type (class name) for any * {@code } tag that might be created */ + @Nullable public Object parsePropertySubElement(Element ele, BeanDefinition bd, String defaultValueType) { if (!isDefaultNamespace(ele)) { return parseNestedCustomElement(ele, bd); @@ -1035,6 +1042,7 @@ public class BeanDefinitionParserDelegate { /** * Return a typed String value Object for the given 'idref' element. */ + @Nullable public Object parseIdRefElement(Element ele) { // A generic reference to any name of any bean. String refName = ele.getAttribute(BEAN_REF_ATTRIBUTE); @@ -1346,6 +1354,7 @@ public class BeanDefinitionParserDelegate { return parseCustomElement(ele, null); } + @Nullable public BeanDefinition parseCustomElement(Element ele, BeanDefinition containingBd) { String namespaceUri = getNamespaceURI(ele); NamespaceHandler handler = this.readerContext.getNamespaceHandlerResolver().resolve(namespaceUri); @@ -1405,6 +1414,7 @@ public class BeanDefinitionParserDelegate { return originalDef; } + @Nullable private BeanDefinitionHolder parseNestedCustomElement(Element ele, BeanDefinition containingBd) { BeanDefinition innerDefinition = parseCustomElement(ele, containingBd); if (innerDefinition == null) { diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/xml/BeansDtdResolver.java b/spring-beans/src/main/java/org/springframework/beans/factory/xml/BeansDtdResolver.java index dba29ca05f..3411deb2c6 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/xml/BeansDtdResolver.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/xml/BeansDtdResolver.java @@ -25,6 +25,7 @@ import org.xml.sax.InputSource; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; +import org.springframework.lang.Nullable; /** * EntityResolver implementation for the Spring beans DTD, @@ -50,6 +51,7 @@ public class BeansDtdResolver implements EntityResolver { @Override + @Nullable public InputSource resolveEntity(String publicId, String systemId) throws IOException { if (logger.isTraceEnabled()) { logger.trace("Trying to resolve XML entity with public ID [" + publicId + diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/xml/DefaultNamespaceHandlerResolver.java b/spring-beans/src/main/java/org/springframework/beans/factory/xml/DefaultNamespaceHandlerResolver.java index 36cda2df71..64540fe751 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/xml/DefaultNamespaceHandlerResolver.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/xml/DefaultNamespaceHandlerResolver.java @@ -27,6 +27,7 @@ import org.apache.commons.logging.LogFactory; import org.springframework.beans.BeanUtils; import org.springframework.beans.FatalBeanException; import org.springframework.core.io.support.PropertiesLoaderUtils; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.CollectionUtils; @@ -85,7 +86,7 @@ public class DefaultNamespaceHandlerResolver implements NamespaceHandlerResolver * (may be {@code null}, in which case the thread context ClassLoader will be used) * @see #DEFAULT_HANDLER_MAPPINGS_LOCATION */ - public DefaultNamespaceHandlerResolver(ClassLoader classLoader) { + public DefaultNamespaceHandlerResolver(@Nullable ClassLoader classLoader) { this(classLoader, DEFAULT_HANDLER_MAPPINGS_LOCATION); } @@ -96,7 +97,7 @@ public class DefaultNamespaceHandlerResolver implements NamespaceHandlerResolver * may be {@code null}, in which case the thread context ClassLoader will be used) * @param handlerMappingsLocation the mapping file location */ - public DefaultNamespaceHandlerResolver(ClassLoader classLoader, String handlerMappingsLocation) { + public DefaultNamespaceHandlerResolver(@Nullable ClassLoader classLoader, String handlerMappingsLocation) { Assert.notNull(handlerMappingsLocation, "Handler mappings location must not be null"); this.classLoader = (classLoader != null ? classLoader : ClassUtils.getDefaultClassLoader()); this.handlerMappingsLocation = handlerMappingsLocation; diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/xml/DelegatingEntityResolver.java b/spring-beans/src/main/java/org/springframework/beans/factory/xml/DelegatingEntityResolver.java index 019b9c16a2..030198636f 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/xml/DelegatingEntityResolver.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/xml/DelegatingEntityResolver.java @@ -22,6 +22,7 @@ import org.xml.sax.EntityResolver; import org.xml.sax.InputSource; import org.xml.sax.SAXException; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -57,7 +58,7 @@ public class DelegatingEntityResolver implements EntityResolver { * @param classLoader the ClassLoader to use for loading * (can be {@code null}) to use the default ClassLoader) */ - public DelegatingEntityResolver(ClassLoader classLoader) { + public DelegatingEntityResolver(@Nullable ClassLoader classLoader) { this.dtdResolver = new BeansDtdResolver(); this.schemaResolver = new PluggableSchemaResolver(classLoader); } @@ -77,6 +78,7 @@ public class DelegatingEntityResolver implements EntityResolver { @Override + @Nullable public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { if (systemId != null) { if (systemId.endsWith(DTD_SUFFIX)) { diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/xml/NamespaceHandler.java b/spring-beans/src/main/java/org/springframework/beans/factory/xml/NamespaceHandler.java index 920a36fde9..bfa0529b3e 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/xml/NamespaceHandler.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/xml/NamespaceHandler.java @@ -21,6 +21,7 @@ import org.w3c.dom.Node; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.BeanDefinitionHolder; +import org.springframework.lang.Nullable; /** * Base interface used by the {@link DefaultBeanDefinitionDocumentReader} @@ -68,6 +69,7 @@ public interface NamespaceHandler { * @param parserContext the object encapsulating the current state of the parsing process * @return the primary {@code BeanDefinition} (can be {@code null} as explained above) */ + @Nullable BeanDefinition parse(Element element, ParserContext parserContext); /** diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/xml/NamespaceHandlerResolver.java b/spring-beans/src/main/java/org/springframework/beans/factory/xml/NamespaceHandlerResolver.java index 7874ed2f19..8237d13a03 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/xml/NamespaceHandlerResolver.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/xml/NamespaceHandlerResolver.java @@ -16,6 +16,8 @@ package org.springframework.beans.factory.xml; +import org.springframework.lang.Nullable; + /** * Used by the {@link org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader} to * locate a {@link NamespaceHandler} implementation for a particular namespace URI. @@ -34,6 +36,7 @@ public interface NamespaceHandlerResolver { * @param namespaceUri the relevant namespace URI * @return the located {@link NamespaceHandler} (may be {@code null}) */ + @Nullable NamespaceHandler resolve(String namespaceUri); } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/xml/PluggableSchemaResolver.java b/spring-beans/src/main/java/org/springframework/beans/factory/xml/PluggableSchemaResolver.java index ebad84b995..a56dc16f07 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/xml/PluggableSchemaResolver.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/xml/PluggableSchemaResolver.java @@ -30,6 +30,7 @@ import org.xml.sax.InputSource; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; import org.springframework.core.io.support.PropertiesLoaderUtils; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; @@ -80,7 +81,7 @@ public class PluggableSchemaResolver implements EntityResolver { * (can be {@code null}) to use the default ClassLoader) * @see PropertiesLoaderUtils#loadAllProperties(String, ClassLoader) */ - public PluggableSchemaResolver(ClassLoader classLoader) { + public PluggableSchemaResolver(@Nullable ClassLoader classLoader) { this.classLoader = classLoader; this.schemaMappingsLocation = DEFAULT_SCHEMA_MAPPINGS_LOCATION; } @@ -94,13 +95,14 @@ public class PluggableSchemaResolver implements EntityResolver { * (must not be empty) * @see PropertiesLoaderUtils#loadAllProperties(String, ClassLoader) */ - public PluggableSchemaResolver(ClassLoader classLoader, String schemaMappingsLocation) { + public PluggableSchemaResolver(@Nullable ClassLoader classLoader, String schemaMappingsLocation) { Assert.hasText(schemaMappingsLocation, "'schemaMappingsLocation' must not be empty"); this.classLoader = classLoader; this.schemaMappingsLocation = schemaMappingsLocation; } @Override + @Nullable public InputSource resolveEntity(String publicId, String systemId) throws IOException { if (logger.isTraceEnabled()) { logger.trace("Trying to resolve XML entity with public id [" + publicId + diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/xml/XmlBeanDefinitionReader.java b/spring-beans/src/main/java/org/springframework/beans/factory/xml/XmlBeanDefinitionReader.java index dbefa35e40..384543fbec 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/xml/XmlBeanDefinitionReader.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/xml/XmlBeanDefinitionReader.java @@ -20,6 +20,7 @@ import java.io.IOException; import java.io.InputStream; import java.util.HashSet; import java.util.Set; + import javax.xml.parsers.ParserConfigurationException; import org.w3c.dom.Document; @@ -45,6 +46,7 @@ import org.springframework.core.io.DescriptiveResource; import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceLoader; import org.springframework.core.io.support.EncodedResource; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.xml.SimpleSaxErrorHandler; import org.springframework.util.xml.XmlValidationModeDetector; @@ -369,7 +371,7 @@ public class XmlBeanDefinitionReader extends AbstractBeanDefinitionReader { * @return the number of bean definitions found * @throws BeanDefinitionStoreException in case of loading or parsing errors */ - public int loadBeanDefinitions(InputSource inputSource, String resourceDescription) + public int loadBeanDefinitions(InputSource inputSource, @Nullable String resourceDescription) throws BeanDefinitionStoreException { return doLoadBeanDefinitions(inputSource, new DescriptiveResource(resourceDescription)); diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/xml/package-info.java b/spring-beans/src/main/java/org/springframework/beans/factory/xml/package-info.java index 8b0070dafe..949b5e791b 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/xml/package-info.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/xml/package-info.java @@ -2,4 +2,7 @@ * Contains an abstract XML-based {@code BeanFactory} implementation, * including a standard "spring-beans" XSD. */ +@NonNullApi package org.springframework.beans.factory.xml; + +import org.springframework.lang.NonNullApi; diff --git a/spring-beans/src/main/java/org/springframework/beans/package-info.java b/spring-beans/src/main/java/org/springframework/beans/package-info.java index 6b4466dbea..e264366a08 100644 --- a/spring-beans/src/main/java/org/springframework/beans/package-info.java +++ b/spring-beans/src/main/java/org/springframework/beans/package-info.java @@ -9,4 +9,7 @@ * Expert One-On-One J2EE Design and Development * by Rod Johnson (Wrox, 2002). */ +@NonNullApi package org.springframework.beans; + +import org.springframework.lang.NonNullApi; diff --git a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/ClassArrayEditor.java b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/ClassArrayEditor.java index c63bb7c00d..bcc1a90a6d 100644 --- a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/ClassArrayEditor.java +++ b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/ClassArrayEditor.java @@ -18,6 +18,7 @@ package org.springframework.beans.propertyeditors; import java.beans.PropertyEditorSupport; +import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; @@ -53,7 +54,7 @@ public class ClassArrayEditor extends PropertyEditorSupport { * @param classLoader the {@code ClassLoader} to use * (or pass {@code null} for the thread context {@code ClassLoader}) */ - public ClassArrayEditor(ClassLoader classLoader) { + public ClassArrayEditor(@Nullable ClassLoader classLoader) { this.classLoader = (classLoader != null ? classLoader : ClassUtils.getDefaultClassLoader()); } diff --git a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/ClassEditor.java b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/ClassEditor.java index 51e630cd9b..fcff9ad064 100644 --- a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/ClassEditor.java +++ b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/ClassEditor.java @@ -18,6 +18,7 @@ package org.springframework.beans.propertyeditors; import java.beans.PropertyEditorSupport; +import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.util.StringUtils; @@ -52,7 +53,7 @@ public class ClassEditor extends PropertyEditorSupport { * @param classLoader the ClassLoader to use * (or {@code null} for the thread context ClassLoader) */ - public ClassEditor(ClassLoader classLoader) { + public ClassEditor(@Nullable ClassLoader classLoader) { this.classLoader = (classLoader != null ? classLoader : ClassUtils.getDefaultClassLoader()); } diff --git a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/CustomCollectionEditor.java b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/CustomCollectionEditor.java index ced9aa043d..303612b465 100644 --- a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/CustomCollectionEditor.java +++ b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/CustomCollectionEditor.java @@ -25,6 +25,7 @@ import java.util.List; import java.util.SortedSet; import java.util.TreeSet; +import org.springframework.lang.Nullable; import org.springframework.util.ReflectionUtils; /** @@ -207,6 +208,7 @@ public class CustomCollectionEditor extends PropertyEditorSupport { * there is no appropriate text representation. */ @Override + @Nullable public String getAsText() { return null; } diff --git a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/CustomMapEditor.java b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/CustomMapEditor.java index afb393576a..1f85ee721e 100644 --- a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/CustomMapEditor.java +++ b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/CustomMapEditor.java @@ -22,6 +22,7 @@ import java.util.Map; import java.util.SortedMap; import java.util.TreeMap; +import org.springframework.lang.Nullable; import org.springframework.util.ReflectionUtils; /** @@ -199,6 +200,7 @@ public class CustomMapEditor extends PropertyEditorSupport { * there is no appropriate text representation. */ @Override + @Nullable public String getAsText() { return null; } diff --git a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/InputStreamEditor.java b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/InputStreamEditor.java index dc9823935a..9d5c854211 100644 --- a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/InputStreamEditor.java +++ b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/InputStreamEditor.java @@ -21,6 +21,7 @@ import java.io.IOException; import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceEditor; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -80,6 +81,7 @@ public class InputStreamEditor extends PropertyEditorSupport { * there is no appropriate text representation. */ @Override + @Nullable public String getAsText() { return null; } diff --git a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/ReaderEditor.java b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/ReaderEditor.java index 894d97709e..bbed9e8579 100644 --- a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/ReaderEditor.java +++ b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/ReaderEditor.java @@ -22,6 +22,7 @@ import java.io.IOException; import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceEditor; import org.springframework.core.io.support.EncodedResource; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -80,6 +81,7 @@ public class ReaderEditor extends PropertyEditorSupport { * there is no appropriate text representation. */ @Override + @Nullable public String getAsText() { return null; } diff --git a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/URIEditor.java b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/URIEditor.java index 7dc173a0d2..56537ca955 100644 --- a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/URIEditor.java +++ b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/URIEditor.java @@ -22,6 +22,7 @@ import java.net.URI; import java.net.URISyntaxException; import org.springframework.core.io.ClassPathResource; +import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.util.ResourceUtils; import org.springframework.util.StringUtils; @@ -79,7 +80,7 @@ public class URIEditor extends PropertyEditorSupport { * @param classLoader the ClassLoader to use for resolving "classpath:" locations * (may be {@code null} to indicate the default ClassLoader) */ - public URIEditor(ClassLoader classLoader) { + public URIEditor(@Nullable ClassLoader classLoader) { this(classLoader, true); } @@ -90,7 +91,7 @@ public class URIEditor extends PropertyEditorSupport { * (may be {@code null} to indicate the default ClassLoader) * @param encode indicates whether Strings will be encoded or not */ - public URIEditor(ClassLoader classLoader, boolean encode) { + public URIEditor(@Nullable ClassLoader classLoader, boolean encode) { this.classLoader = (classLoader != null ? classLoader : ClassUtils.getDefaultClassLoader()); this.encode = encode; } diff --git a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/package-info.java b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/package-info.java index 755aee3ae8..45e18cc851 100644 --- a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/package-info.java +++ b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/package-info.java @@ -6,4 +6,7 @@ * "CustomXxxEditor" classes are intended for manual registration in * specific binding processes, as they are localized or the like. */ +@NonNullApi package org.springframework.beans.propertyeditors; + +import org.springframework.lang.NonNullApi; diff --git a/spring-beans/src/main/java/org/springframework/beans/support/ArgumentConvertingMethodInvoker.java b/spring-beans/src/main/java/org/springframework/beans/support/ArgumentConvertingMethodInvoker.java index ebdf6a494b..72912d5e32 100644 --- a/spring-beans/src/main/java/org/springframework/beans/support/ArgumentConvertingMethodInvoker.java +++ b/spring-beans/src/main/java/org/springframework/beans/support/ArgumentConvertingMethodInvoker.java @@ -23,6 +23,7 @@ import org.springframework.beans.PropertyEditorRegistry; import org.springframework.beans.SimpleTypeConverter; import org.springframework.beans.TypeConverter; import org.springframework.beans.TypeMismatchException; +import org.springframework.lang.Nullable; import org.springframework.util.MethodInvoker; import org.springframework.util.ReflectionUtils; @@ -127,6 +128,7 @@ public class ArgumentConvertingMethodInvoker extends MethodInvoker { * @param arguments the argument values to match against method parameters * @return a matching method, or {@code null} if none */ + @Nullable protected Method doFindMatchingMethod(Object[] arguments) { TypeConverter converter = getTypeConverter(); if (converter != null) { diff --git a/spring-beans/src/main/java/org/springframework/beans/support/PropertyComparator.java b/spring-beans/src/main/java/org/springframework/beans/support/PropertyComparator.java index c50251174e..6eb876a3c1 100644 --- a/spring-beans/src/main/java/org/springframework/beans/support/PropertyComparator.java +++ b/spring-beans/src/main/java/org/springframework/beans/support/PropertyComparator.java @@ -26,6 +26,7 @@ import org.apache.commons.logging.LogFactory; import org.springframework.beans.BeanWrapperImpl; import org.springframework.beans.BeansException; +import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; /** @@ -108,6 +109,7 @@ public class PropertyComparator implements Comparator { * @param obj the object to get the property value for * @return the property value */ + @Nullable private Object getPropertyValue(Object obj) { // If a nested property cannot be read, simply return null // (similar to JSTL EL). If the property doesn't exist in the diff --git a/spring-beans/src/main/java/org/springframework/beans/support/package-info.java b/spring-beans/src/main/java/org/springframework/beans/support/package-info.java index a4679c4737..7147fd0293 100644 --- a/spring-beans/src/main/java/org/springframework/beans/support/package-info.java +++ b/spring-beans/src/main/java/org/springframework/beans/support/package-info.java @@ -2,4 +2,7 @@ * Classes supporting the org.springframework.beans package, * such as utility classes for sorting and holding lists of beans. */ +@NonNullApi package org.springframework.beans.support; + +import org.springframework.lang.NonNullApi; diff --git a/spring-context-support/src/main/java/org/springframework/cache/caffeine/CaffeineCacheManager.java b/spring-context-support/src/main/java/org/springframework/cache/caffeine/CaffeineCacheManager.java index 15ebcb91ac..f09322f602 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/caffeine/CaffeineCacheManager.java +++ b/spring-context-support/src/main/java/org/springframework/cache/caffeine/CaffeineCacheManager.java @@ -29,6 +29,7 @@ import com.github.benmanes.caffeine.cache.CaffeineSpec; import org.springframework.cache.Cache; import org.springframework.cache.CacheManager; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; @@ -88,7 +89,7 @@ public class CaffeineCacheManager implements CacheManager { *

Calling this with a {@code null} collection argument resets the * mode to 'dynamic', allowing for further creation of caches again. */ - public void setCacheNames(Collection cacheNames) { + public void setCacheNames(@Nullable Collection cacheNames) { if (cacheNames != null) { for (String name : cacheNames) { this.cacheMap.put(name, createCaffeineCache(name)); diff --git a/spring-context-support/src/main/java/org/springframework/cache/caffeine/package-info.java b/spring-context-support/src/main/java/org/springframework/cache/caffeine/package-info.java index 786880a748..e98cf7f00c 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/caffeine/package-info.java +++ b/spring-context-support/src/main/java/org/springframework/cache/caffeine/package-info.java @@ -3,4 +3,7 @@ * Caffeine library, * allowing to set up Caffeine caches within Spring's cache abstraction. */ +@NonNullApi package org.springframework.cache.caffeine; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context-support/src/main/java/org/springframework/cache/ehcache/package-info.java b/spring-context-support/src/main/java/org/springframework/cache/ehcache/package-info.java index edb951a4ce..ba15c19701 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/ehcache/package-info.java +++ b/spring-context-support/src/main/java/org/springframework/cache/ehcache/package-info.java @@ -9,4 +9,7 @@ * Instead, consider using it through JCache (JSR-107), with * Spring's support in {@code org.springframework.cache.jcache}. */ +@NonNullApi package org.springframework.cache.ehcache; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context-support/src/main/java/org/springframework/cache/jcache/JCacheManagerFactoryBean.java b/spring-context-support/src/main/java/org/springframework/cache/jcache/JCacheManagerFactoryBean.java index 1de64fbb42..1b58aa9da3 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/jcache/JCacheManagerFactoryBean.java +++ b/spring-context-support/src/main/java/org/springframework/cache/jcache/JCacheManagerFactoryBean.java @@ -25,6 +25,7 @@ import org.springframework.beans.factory.BeanClassLoaderAware; import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.InitializingBean; +import org.springframework.lang.Nullable; /** * {@link FactoryBean} for a JCache {@link javax.cache.CacheManager}, @@ -54,7 +55,7 @@ public class JCacheManagerFactoryBean * Specify the URI for the desired CacheManager. * Default is {@code null} (i.e. JCache's default). */ - public void setCacheManagerUri(URI cacheManagerUri) { + public void setCacheManagerUri(@Nullable URI cacheManagerUri) { this.cacheManagerUri = cacheManagerUri; } @@ -63,7 +64,7 @@ public class JCacheManagerFactoryBean * Default is {@code null} (i.e. no special properties to apply). * @see javax.cache.spi.CachingProvider#getCacheManager(URI, ClassLoader, Properties) */ - public void setCacheManagerProperties(Properties cacheManagerProperties) { + public void setCacheManagerProperties(@Nullable Properties cacheManagerProperties) { this.cacheManagerProperties = cacheManagerProperties; } diff --git a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/AbstractCacheInterceptor.java b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/AbstractCacheInterceptor.java index 800ceeec14..3fc4e4f56a 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/AbstractCacheInterceptor.java +++ b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/AbstractCacheInterceptor.java @@ -28,6 +28,7 @@ import org.springframework.cache.interceptor.AbstractCacheInvoker; import org.springframework.cache.interceptor.CacheErrorHandler; import org.springframework.cache.interceptor.CacheOperationInvocationContext; import org.springframework.cache.interceptor.CacheOperationInvoker; +import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; /** @@ -71,6 +72,7 @@ abstract class AbstractCacheInterceptor, A *

Throw an {@link IllegalStateException} if the collection holds more than one element * @return the single element or {@code null} if the collection is empty */ + @Nullable static Cache extractFrom(Collection caches) { if (CollectionUtils.isEmpty(caches)) { return null; diff --git a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/AbstractFallbackJCacheOperationSource.java b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/AbstractFallbackJCacheOperationSource.java index 875a55540d..3466475a03 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/AbstractFallbackJCacheOperationSource.java +++ b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/AbstractFallbackJCacheOperationSource.java @@ -26,6 +26,7 @@ import org.apache.commons.logging.LogFactory; import org.springframework.core.BridgeMethodResolver; import org.springframework.core.MethodClassKey; +import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; /** @@ -77,6 +78,7 @@ public abstract class AbstractFallbackJCacheOperationSource implements JCacheOpe } } + @Nullable private JCacheOperation computeCacheOperation(Method method, Class targetClass) { // Don't allow no-public methods as required. if (allowPublicMethodsOnly() && !Modifier.isPublic(method.getModifiers())) { @@ -113,6 +115,7 @@ public abstract class AbstractFallbackJCacheOperationSource implements JCacheOpe * @return the cache operation associated with this method * (or {@code null} if none) */ + @Nullable protected abstract JCacheOperation findCacheOperation(Method method, Class targetType); /** diff --git a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/AnnotationJCacheOperationSource.java b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/AnnotationJCacheOperationSource.java index 9f75bce7c9..0ebf93a71f 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/AnnotationJCacheOperationSource.java +++ b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/AnnotationJCacheOperationSource.java @@ -31,6 +31,7 @@ import javax.cache.annotation.CacheResult; import org.springframework.cache.interceptor.CacheResolver; import org.springframework.cache.interceptor.KeyGenerator; +import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; /** @@ -157,6 +158,7 @@ public abstract class AnnotationJCacheOperationSource extends AbstractFallbackJC } } + @Nullable protected CacheResolverFactory determineCacheResolverFactory(CacheDefaults defaults, Class candidate) { diff --git a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/CacheResultInterceptor.java b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/CacheResultInterceptor.java index 3f01b009c0..6cdf120ee7 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/CacheResultInterceptor.java +++ b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/CacheResultInterceptor.java @@ -23,6 +23,7 @@ import org.springframework.cache.interceptor.CacheErrorHandler; import org.springframework.cache.interceptor.CacheOperationInvocationContext; import org.springframework.cache.interceptor.CacheOperationInvoker; import org.springframework.cache.interceptor.CacheResolver; +import org.springframework.lang.Nullable; import org.springframework.util.ExceptionTypeFilter; import org.springframework.util.SerializationUtils; @@ -92,6 +93,7 @@ class CacheResultInterceptor extends AbstractKeyCacheInterceptor context) { CacheResolver exceptionCacheResolver = context.getOperation().getExceptionCacheResolver(); if (exceptionCacheResolver != null) { diff --git a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/CacheResultOperation.java b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/CacheResultOperation.java index 314fdc62a1..f421dfe850 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/CacheResultOperation.java +++ b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/CacheResultOperation.java @@ -21,6 +21,7 @@ import javax.cache.annotation.CacheResult; import org.springframework.cache.interceptor.CacheResolver; import org.springframework.cache.interceptor.KeyGenerator; +import org.springframework.lang.Nullable; import org.springframework.util.ExceptionTypeFilter; import org.springframework.util.StringUtils; @@ -78,6 +79,7 @@ class CacheResultOperation extends AbstractJCacheKeyOperation { * caching exceptions should be disabled. * @see javax.cache.annotation.CacheResult#exceptionCacheName() */ + @Nullable public String getExceptionCacheName() { return this.exceptionCacheName; } diff --git a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/DefaultJCacheOperationSource.java b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/DefaultJCacheOperationSource.java index acc1a12ec7..efe4c2fe06 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/DefaultJCacheOperationSource.java +++ b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/DefaultJCacheOperationSource.java @@ -32,6 +32,7 @@ import org.springframework.cache.interceptor.CacheResolver; import org.springframework.cache.interceptor.KeyGenerator; import org.springframework.cache.interceptor.SimpleCacheResolver; import org.springframework.cache.interceptor.SimpleKeyGenerator; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -69,6 +70,7 @@ public class DefaultJCacheOperationSource extends AnnotationJCacheOperationSourc /** * Return the specified cache manager to use, if any. */ + @Nullable public CacheManager getCacheManager() { return this.cacheManager; } @@ -84,6 +86,7 @@ public class DefaultJCacheOperationSource extends AnnotationJCacheOperationSourc /** * Return the specified cache resolver to use, if any. */ + @Nullable public CacheResolver getCacheResolver() { return this.cacheResolver; } @@ -99,6 +102,7 @@ public class DefaultJCacheOperationSource extends AnnotationJCacheOperationSourc /** * Return the specified exception cache resolver to use, if any. */ + @Nullable public CacheResolver getExceptionCacheResolver() { return this.exceptionCacheResolver; } @@ -115,6 +119,7 @@ public class DefaultJCacheOperationSource extends AnnotationJCacheOperationSourc /** * Return the specified key generator to use, if any. */ + @Nullable public KeyGenerator getKeyGenerator() { return this.keyGenerator; } diff --git a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/JCacheOperationSource.java b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/JCacheOperationSource.java index 36177dda86..5139282c1d 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/JCacheOperationSource.java +++ b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/JCacheOperationSource.java @@ -18,6 +18,8 @@ package org.springframework.cache.jcache.interceptor; import java.lang.reflect.Method; +import org.springframework.lang.Nullable; + /** * Interface used by {@link JCacheInterceptor}. Implementations know how to source * cache operation attributes from standard JSR-107 annotations. @@ -37,6 +39,7 @@ public interface JCacheOperationSource { * the declaring class of the method must be used) * @return the cache operation for this method, or {@code null} if none found */ - JCacheOperation getCacheOperation(Method method, Class targetClass); + @Nullable + JCacheOperation getCacheOperation(Method method, @Nullable Class targetClass); } diff --git a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/JCacheOperationSourcePointcut.java b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/JCacheOperationSourcePointcut.java index ad19123e17..46fbd7439b 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/JCacheOperationSourcePointcut.java +++ b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/JCacheOperationSourcePointcut.java @@ -20,6 +20,7 @@ import java.io.Serializable; import java.lang.reflect.Method; import org.springframework.aop.support.StaticMethodMatcherPointcut; +import org.springframework.lang.Nullable; import org.springframework.util.ObjectUtils; /** @@ -43,6 +44,7 @@ public abstract class JCacheOperationSourcePointcut * Obtain the underlying {@link JCacheOperationSource} (may be {@code null}). * To be implemented by subclasses. */ + @Nullable protected abstract JCacheOperationSource getCacheOperationSource(); @Override diff --git a/spring-context-support/src/main/java/org/springframework/cache/jcache/package-info.java b/spring-context-support/src/main/java/org/springframework/cache/jcache/package-info.java index 59393e85a1..aedc6c65c1 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/jcache/package-info.java +++ b/spring-context-support/src/main/java/org/springframework/cache/jcache/package-info.java @@ -4,4 +4,7 @@ * and {@link org.springframework.cache.Cache Cache} implementation for * use in a Spring context, using a JSR-107 compliant cache provider. */ +@NonNullApi package org.springframework.cache.jcache; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context-support/src/main/java/org/springframework/cache/transaction/package-info.java b/spring-context-support/src/main/java/org/springframework/cache/transaction/package-info.java index 7d210e6fdf..89b7e74dd2 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/transaction/package-info.java +++ b/spring-context-support/src/main/java/org/springframework/cache/transaction/package-info.java @@ -2,4 +2,7 @@ * Transaction-aware decorators for the org.springframework.cache package. * Provides synchronization of put operations with Spring-managed transactions. */ +@NonNullApi package org.springframework.cache.transaction; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context-support/src/main/java/org/springframework/mail/javamail/ConfigurableMimeFileTypeMap.java b/spring-context-support/src/main/java/org/springframework/mail/javamail/ConfigurableMimeFileTypeMap.java index eb3f67ce6b..75761a38e7 100644 --- a/spring-context-support/src/main/java/org/springframework/mail/javamail/ConfigurableMimeFileTypeMap.java +++ b/spring-context-support/src/main/java/org/springframework/mail/javamail/ConfigurableMimeFileTypeMap.java @@ -25,6 +25,7 @@ import javax.activation.MimetypesFileTypeMap; import org.springframework.beans.factory.InitializingBean; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; +import org.springframework.lang.Nullable; /** * Spring-configurable {@code FileTypeMap} implementation that will read @@ -139,7 +140,7 @@ public class ConfigurableMimeFileTypeMap extends FileTypeMap implements Initiali * @see javax.activation.MimetypesFileTypeMap#MimetypesFileTypeMap(java.io.InputStream) * @see javax.activation.MimetypesFileTypeMap#addMimeTypes(String) */ - protected FileTypeMap createFileTypeMap(Resource mappingLocation, String[] mappings) throws IOException { + protected FileTypeMap createFileTypeMap(@Nullable Resource mappingLocation, @Nullable String[] mappings) throws IOException { MimetypesFileTypeMap fileTypeMap = null; if (mappingLocation != null) { InputStream is = mappingLocation.getInputStream(); diff --git a/spring-context-support/src/main/java/org/springframework/mail/javamail/JavaMailSenderImpl.java b/spring-context-support/src/main/java/org/springframework/mail/javamail/JavaMailSenderImpl.java index 7107f1f6c1..b2adc8516a 100644 --- a/spring-context-support/src/main/java/org/springframework/mail/javamail/JavaMailSenderImpl.java +++ b/spring-context-support/src/main/java/org/springframework/mail/javamail/JavaMailSenderImpl.java @@ -31,6 +31,7 @@ import javax.mail.Session; import javax.mail.Transport; import javax.mail.internet.MimeMessage; +import org.springframework.lang.Nullable; import org.springframework.mail.MailAuthenticationException; import org.springframework.mail.MailException; import org.springframework.mail.MailParseException; @@ -218,6 +219,7 @@ public class JavaMailSenderImpl implements JavaMailSender { /** * Return the username for the account at the mail host. */ + @Nullable public String getUsername() { return this.username; } @@ -240,6 +242,7 @@ public class JavaMailSenderImpl implements JavaMailSender { /** * Return the password for the account at the mail host. */ + @Nullable public String getPassword() { return this.password; } @@ -257,6 +260,7 @@ public class JavaMailSenderImpl implements JavaMailSender { * Return the default encoding for {@link MimeMessage MimeMessages}, * or {@code null} if none. */ + @Nullable public String getDefaultEncoding() { return this.defaultEncoding; } @@ -282,6 +286,7 @@ public class JavaMailSenderImpl implements JavaMailSender { * Return the default Java Activation {@link FileTypeMap} for * {@link MimeMessage MimeMessages}, or {@code null} if none. */ + @Nullable public FileTypeMap getDefaultFileTypeMap() { return this.defaultFileTypeMap; } diff --git a/spring-context-support/src/main/java/org/springframework/mail/javamail/MimeMessageHelper.java b/spring-context-support/src/main/java/org/springframework/mail/javamail/MimeMessageHelper.java index 9b755e843e..68526e85d7 100644 --- a/spring-context-support/src/main/java/org/springframework/mail/javamail/MimeMessageHelper.java +++ b/spring-context-support/src/main/java/org/springframework/mail/javamail/MimeMessageHelper.java @@ -39,6 +39,7 @@ import javax.mail.internet.MimeUtility; import org.springframework.core.io.InputStreamSource; import org.springframework.core.io.Resource; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -361,7 +362,7 @@ public class MimeMessageHelper { * will be added to (can be the same as the root multipart object, or an element * nested underneath the root multipart element) */ - protected final void setMimeMultiparts(MimeMultipart root, MimeMultipart main) { + protected final void setMimeMultiparts(@Nullable MimeMultipart root, MimeMultipart main) { this.rootMimeMultipart = root; this.mimeMultipart = main; } @@ -423,6 +424,7 @@ public class MimeMessageHelper { * @return the default encoding associated with the MimeMessage, * or {@code null} if none found */ + @Nullable protected String getDefaultEncoding(MimeMessage mimeMessage) { if (mimeMessage instanceof SmartMimeMessage) { return ((SmartMimeMessage) mimeMessage).getDefaultEncoding(); @@ -433,6 +435,7 @@ public class MimeMessageHelper { /** * Return the specific character encoding used for this message, if any. */ + @Nullable public String getEncoding() { return this.encoding; } diff --git a/spring-context-support/src/main/java/org/springframework/mail/javamail/SmartMimeMessage.java b/spring-context-support/src/main/java/org/springframework/mail/javamail/SmartMimeMessage.java index 35b3ace313..d17a10ab95 100644 --- a/spring-context-support/src/main/java/org/springframework/mail/javamail/SmartMimeMessage.java +++ b/spring-context-support/src/main/java/org/springframework/mail/javamail/SmartMimeMessage.java @@ -20,6 +20,8 @@ import javax.activation.FileTypeMap; import javax.mail.Session; import javax.mail.internet.MimeMessage; +import org.springframework.lang.Nullable; + /** * Special subclass of the standard JavaMail {@link MimeMessage}, carrying a * default encoding to be used when populating the message and a default Java @@ -48,7 +50,7 @@ class SmartMimeMessage extends MimeMessage { * @param defaultEncoding the default encoding, or {@code null} if none * @param defaultFileTypeMap the default FileTypeMap, or {@code null} if none */ - public SmartMimeMessage(Session session, String defaultEncoding, FileTypeMap defaultFileTypeMap) { + public SmartMimeMessage(Session session, @Nullable String defaultEncoding, @Nullable FileTypeMap defaultFileTypeMap) { super(session); this.defaultEncoding = defaultEncoding; this.defaultFileTypeMap = defaultFileTypeMap; @@ -58,6 +60,7 @@ class SmartMimeMessage extends MimeMessage { /** * Return the default encoding of this message, or {@code null} if none. */ + @Nullable public final String getDefaultEncoding() { return this.defaultEncoding; } @@ -65,6 +68,7 @@ class SmartMimeMessage extends MimeMessage { /** * Return the default FileTypeMap of this message, or {@code null} if none. */ + @Nullable public final FileTypeMap getDefaultFileTypeMap() { return this.defaultFileTypeMap; } diff --git a/spring-context-support/src/main/java/org/springframework/mail/javamail/package-info.java b/spring-context-support/src/main/java/org/springframework/mail/javamail/package-info.java index 44d9ed12c5..ea2101475c 100644 --- a/spring-context-support/src/main/java/org/springframework/mail/javamail/package-info.java +++ b/spring-context-support/src/main/java/org/springframework/mail/javamail/package-info.java @@ -3,4 +3,7 @@ * Provides an extended JavaMailSender interface and a MimeMessageHelper * class for convenient population of a JavaMail MimeMessage. */ +@NonNullApi package org.springframework.mail.javamail; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context-support/src/main/java/org/springframework/mail/package-info.java b/spring-context-support/src/main/java/org/springframework/mail/package-info.java index c9a94c5c78..cf4d9360f7 100644 --- a/spring-context-support/src/main/java/org/springframework/mail/package-info.java +++ b/spring-context-support/src/main/java/org/springframework/mail/package-info.java @@ -2,4 +2,7 @@ * Spring's generic mail infrastructure. * Concrete implementations are provided in the subpackages. */ +@NonNullApi package org.springframework.mail; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context-support/src/main/java/org/springframework/scheduling/commonj/TimerManagerTaskScheduler.java b/spring-context-support/src/main/java/org/springframework/scheduling/commonj/TimerManagerTaskScheduler.java index 2d392dea32..a2dc1b8d4b 100644 --- a/spring-context-support/src/main/java/org/springframework/scheduling/commonj/TimerManagerTaskScheduler.java +++ b/spring-context-support/src/main/java/org/springframework/scheduling/commonj/TimerManagerTaskScheduler.java @@ -25,6 +25,7 @@ import java.util.concurrent.TimeUnit; import commonj.timers.Timer; import commonj.timers.TimerListener; +import org.springframework.lang.Nullable; import org.springframework.scheduling.TaskScheduler; import org.springframework.scheduling.Trigger; import org.springframework.scheduling.support.SimpleTriggerContext; @@ -164,6 +165,7 @@ public class TimerManagerTaskScheduler extends TimerManagerAccessor implements T this.trigger = trigger; } + @Nullable public ScheduledFuture schedule() { this.scheduledExecutionTime = this.trigger.nextExecutionTime(this.triggerContext); if (this.scheduledExecutionTime == null) { diff --git a/spring-context-support/src/main/java/org/springframework/scheduling/commonj/package-info.java b/spring-context-support/src/main/java/org/springframework/scheduling/commonj/package-info.java index ad5b35f30b..edaf056d5b 100644 --- a/spring-context-support/src/main/java/org/springframework/scheduling/commonj/package-info.java +++ b/spring-context-support/src/main/java/org/springframework/scheduling/commonj/package-info.java @@ -2,4 +2,7 @@ * Convenience classes for scheduling based on the CommonJ WorkManager/TimerManager * facility, as supported by IBM WebSphere 6.0+ and BEA WebLogic 9.0+. */ +@NonNullApi package org.springframework.scheduling.commonj; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context-support/src/main/java/org/springframework/scheduling/quartz/ResourceLoaderClassLoadHelper.java b/spring-context-support/src/main/java/org/springframework/scheduling/quartz/ResourceLoaderClassLoadHelper.java index 726f9732d7..dcc0d764aa 100644 --- a/spring-context-support/src/main/java/org/springframework/scheduling/quartz/ResourceLoaderClassLoadHelper.java +++ b/spring-context-support/src/main/java/org/springframework/scheduling/quartz/ResourceLoaderClassLoadHelper.java @@ -27,6 +27,7 @@ import org.quartz.spi.ClassLoadHelper; import org.springframework.core.io.DefaultResourceLoader; import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceLoader; +import org.springframework.lang.Nullable; /** * Wrapper that adapts from the Quartz {@link ClassLoadHelper} interface @@ -82,6 +83,7 @@ public class ResourceLoaderClassLoadHelper implements ClassLoadHelper { } @Override + @Nullable public URL getResource(String name) { Resource resource = this.resourceLoader.getResource(name); if (resource.exists()) { @@ -101,6 +103,7 @@ public class ResourceLoaderClassLoadHelper implements ClassLoadHelper { } @Override + @Nullable public InputStream getResourceAsStream(String name) { Resource resource = this.resourceLoader.getResource(name); if (resource.exists()) { diff --git a/spring-context-support/src/main/java/org/springframework/scheduling/quartz/SpringBeanJobFactory.java b/spring-context-support/src/main/java/org/springframework/scheduling/quartz/SpringBeanJobFactory.java index e4dbef0d3e..4c13e1478b 100644 --- a/spring-context-support/src/main/java/org/springframework/scheduling/quartz/SpringBeanJobFactory.java +++ b/spring-context-support/src/main/java/org/springframework/scheduling/quartz/SpringBeanJobFactory.java @@ -22,6 +22,7 @@ import org.quartz.spi.TriggerFiredBundle; import org.springframework.beans.BeanWrapper; import org.springframework.beans.MutablePropertyValues; import org.springframework.beans.PropertyAccessorFactory; +import org.springframework.lang.Nullable; /** * Subclass of {@link AdaptableJobFactory} that also supports Spring-style @@ -55,7 +56,7 @@ public class SpringBeanJobFactory extends AdaptableJobFactory implements Schedul * ignored if there is no corresponding property found on the particular * job class (all other unknown properties will still trigger an exception). */ - public void setIgnoredUnknownProperties(String... ignoredUnknownProperties) { + public void setIgnoredUnknownProperties(@Nullable String... ignoredUnknownProperties) { this.ignoredUnknownProperties = ignoredUnknownProperties; } diff --git a/spring-context-support/src/main/java/org/springframework/scheduling/quartz/package-info.java b/spring-context-support/src/main/java/org/springframework/scheduling/quartz/package-info.java index df50ca80d7..3681e86d3b 100644 --- a/spring-context-support/src/main/java/org/springframework/scheduling/quartz/package-info.java +++ b/spring-context-support/src/main/java/org/springframework/scheduling/quartz/package-info.java @@ -5,4 +5,7 @@ * Triggers as beans in a Spring context. Also provides * convenience classes for implementing Quartz Jobs. */ +@NonNullApi package org.springframework.scheduling.quartz; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context-support/src/main/java/org/springframework/ui/freemarker/FreeMarkerConfigurationFactory.java b/spring-context-support/src/main/java/org/springframework/ui/freemarker/FreeMarkerConfigurationFactory.java index 9d114f4d1f..dde83abf13 100644 --- a/spring-context-support/src/main/java/org/springframework/ui/freemarker/FreeMarkerConfigurationFactory.java +++ b/spring-context-support/src/main/java/org/springframework/ui/freemarker/FreeMarkerConfigurationFactory.java @@ -38,6 +38,7 @@ import org.springframework.core.io.DefaultResourceLoader; import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceLoader; import org.springframework.core.io.support.PropertiesLoaderUtils; +import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; /** @@ -380,6 +381,7 @@ public class FreeMarkerConfigurationFactory { * @param templateLoaders the final List of TemplateLoader instances * @return the aggregate TemplateLoader */ + @Nullable protected TemplateLoader getAggregateTemplateLoader(List templateLoaders) { int loaderCount = templateLoaders.size(); switch (loaderCount) { diff --git a/spring-context-support/src/main/java/org/springframework/ui/freemarker/package-info.java b/spring-context-support/src/main/java/org/springframework/ui/freemarker/package-info.java index 28fbe3bf51..d7cb60f3ad 100644 --- a/spring-context-support/src/main/java/org/springframework/ui/freemarker/package-info.java +++ b/spring-context-support/src/main/java/org/springframework/ui/freemarker/package-info.java @@ -3,4 +3,7 @@ * FreeMarker * within a Spring application context. */ +@NonNullApi package org.springframework.ui.freemarker; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context/src/main/java/org/springframework/cache/Cache.java b/spring-context/src/main/java/org/springframework/cache/Cache.java index 3124461b2e..78a9cd6b13 100644 --- a/spring-context/src/main/java/org/springframework/cache/Cache.java +++ b/spring-context/src/main/java/org/springframework/cache/Cache.java @@ -18,6 +18,8 @@ package org.springframework.cache; import java.util.concurrent.Callable; +import org.springframework.lang.Nullable; + /** * Interface that defines common cache operations. * @@ -54,7 +56,8 @@ public interface Cache { * returned means that the cache contains no mapping for this key. * @see #get(Object, Class) */ - ValueWrapper get(Object key); + @Nullable + ValueWrapper get(@Nullable Object key); /** * Return the value to which this cache maps the specified key, @@ -74,7 +77,8 @@ public interface Cache { * @since 4.0 * @see #get(Object) */ - T get(Object key, Class type); + @Nullable + T get(@Nullable Object key, Class type); /** * Return the value to which this cache maps the specified key, obtaining @@ -91,7 +95,8 @@ public interface Cache { * @throws ValueRetrievalException if the {@code valueLoader} throws an exception * @since 4.3 */ - T get(Object key, Callable valueLoader); + @Nullable + T get(@Nullable Object key, Callable valueLoader); /** * Associate the specified value with the specified key in this cache. @@ -100,7 +105,7 @@ public interface Cache { * @param key the key with which the specified value is to be associated * @param value the value to be associated with the specified key */ - void put(Object key, Object value); + void put(@Nullable Object key, @Nullable Object value); /** * Atomically associate the specified value with the specified key in this cache @@ -128,13 +133,14 @@ public interface Cache { * an indicator that the given {@code value} has been associated with the key. * @since 4.1 */ - ValueWrapper putIfAbsent(Object key, Object value); + @Nullable + ValueWrapper putIfAbsent(@Nullable Object key, @Nullable Object value); /** * Evict the mapping for this key from this cache if it is present. * @param key the key whose mapping is to be removed from the cache */ - void evict(Object key); + void evict(@Nullable Object key); /** * Remove all mappings from the cache. @@ -151,7 +157,7 @@ public interface Cache { /** * Return the actual value in the cache. */ - Object get(); + @Nullable Object get(); } @@ -165,11 +171,12 @@ public interface Cache { private final Object key; - public ValueRetrievalException(Object key, Callable loader, Throwable ex) { + public ValueRetrievalException(@Nullable Object key, Callable loader, Throwable ex) { super(String.format("Value for key '%s' could not be loaded using '%s'", key, loader), ex); this.key = key; } + @Nullable public Object getKey() { return this.key; } diff --git a/spring-context/src/main/java/org/springframework/cache/CacheManager.java b/spring-context/src/main/java/org/springframework/cache/CacheManager.java index 205bc9a327..fffb6bc2bd 100644 --- a/spring-context/src/main/java/org/springframework/cache/CacheManager.java +++ b/spring-context/src/main/java/org/springframework/cache/CacheManager.java @@ -18,6 +18,8 @@ package org.springframework.cache; import java.util.Collection; +import org.springframework.lang.Nullable; + /** * Spring's central cache manager SPI. * Allows for retrieving named {@link Cache} regions. @@ -32,6 +34,7 @@ public interface CacheManager { * @param name the cache identifier (must not be {@code null}) * @return the associated cache, or {@code null} if none found */ + @Nullable Cache getCache(String name); /** diff --git a/spring-context/src/main/java/org/springframework/cache/annotation/AnnotationCacheOperationSource.java b/spring-context/src/main/java/org/springframework/cache/annotation/AnnotationCacheOperationSource.java index cbb4570f62..68ce9c8530 100644 --- a/spring-context/src/main/java/org/springframework/cache/annotation/AnnotationCacheOperationSource.java +++ b/spring-context/src/main/java/org/springframework/cache/annotation/AnnotationCacheOperationSource.java @@ -26,6 +26,7 @@ import java.util.Set; import org.springframework.cache.interceptor.AbstractFallbackCacheOperationSource; import org.springframework.cache.interceptor.CacheOperation; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -135,6 +136,7 @@ public class AnnotationCacheOperationSource extends AbstractFallbackCacheOperati * @param provider the cache operation provider to use * @return the configured caching operations, or {@code null} if none found */ + @Nullable protected Collection determineCacheOperations(CacheOperationProvider provider) { Collection ops = null; for (CacheAnnotationParser annotationParser : this.annotationParsers) { @@ -189,6 +191,7 @@ public class AnnotationCacheOperationSource extends AbstractFallbackCacheOperati * @param parser the parser to use * @return the cache operations, or {@code null} if none found */ + @Nullable Collection getCacheOperations(CacheAnnotationParser parser); } diff --git a/spring-context/src/main/java/org/springframework/cache/annotation/CacheAnnotationParser.java b/spring-context/src/main/java/org/springframework/cache/annotation/CacheAnnotationParser.java index 80bafb871a..b602b8f424 100644 --- a/spring-context/src/main/java/org/springframework/cache/annotation/CacheAnnotationParser.java +++ b/spring-context/src/main/java/org/springframework/cache/annotation/CacheAnnotationParser.java @@ -20,6 +20,7 @@ import java.lang.reflect.Method; import java.util.Collection; import org.springframework.cache.interceptor.CacheOperation; +import org.springframework.lang.Nullable; /** * Strategy interface for parsing known caching annotation types. @@ -44,6 +45,7 @@ public interface CacheAnnotationParser { * or {@code null} if none was found * @see AnnotationCacheOperationSource#findCacheOperations(Class) */ + @Nullable Collection parseCacheAnnotations(Class type); /** @@ -57,5 +59,6 @@ public interface CacheAnnotationParser { * or {@code null} if none was found * @see AnnotationCacheOperationSource#findCacheOperations(Method) */ + @Nullable Collection parseCacheAnnotations(Method method); } diff --git a/spring-context/src/main/java/org/springframework/cache/annotation/CachingConfigurer.java b/spring-context/src/main/java/org/springframework/cache/annotation/CachingConfigurer.java index 97cfff7acb..348281fbe1 100644 --- a/spring-context/src/main/java/org/springframework/cache/annotation/CachingConfigurer.java +++ b/spring-context/src/main/java/org/springframework/cache/annotation/CachingConfigurer.java @@ -20,6 +20,7 @@ import org.springframework.cache.CacheManager; import org.springframework.cache.interceptor.CacheErrorHandler; import org.springframework.cache.interceptor.CacheResolver; import org.springframework.cache.interceptor.KeyGenerator; +import org.springframework.lang.Nullable; /** * Interface to be implemented by @{@link org.springframework.context.annotation.Configuration @@ -61,6 +62,7 @@ public interface CachingConfigurer { * * See @{@link EnableCaching} for more complete examples. */ + @Nullable CacheManager cacheManager(); /** @@ -85,6 +87,7 @@ public interface CachingConfigurer { * * See {@link EnableCaching} for more complete examples. */ + @Nullable CacheResolver cacheResolver(); /** @@ -105,6 +108,7 @@ public interface CachingConfigurer { * * See @{@link EnableCaching} for more complete examples. */ + @Nullable KeyGenerator keyGenerator(); /** @@ -127,6 +131,7 @@ public interface CachingConfigurer { * * See @{@link EnableCaching} for more complete examples. */ + @Nullable CacheErrorHandler errorHandler(); } diff --git a/spring-context/src/main/java/org/springframework/cache/annotation/package-info.java b/spring-context/src/main/java/org/springframework/cache/annotation/package-info.java index 52bd2a3586..fe4e17c50a 100644 --- a/spring-context/src/main/java/org/springframework/cache/annotation/package-info.java +++ b/spring-context/src/main/java/org/springframework/cache/annotation/package-info.java @@ -3,4 +3,7 @@ * Hooked into Spring's cache interception infrastructure via * {@link org.springframework.cache.interceptor.CacheOperationSource}. */ +@NonNullApi package org.springframework.cache.annotation; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context/src/main/java/org/springframework/cache/concurrent/ConcurrentMapCache.java b/spring-context/src/main/java/org/springframework/cache/concurrent/ConcurrentMapCache.java index c43499ceae..4ea72404b1 100644 --- a/spring-context/src/main/java/org/springframework/cache/concurrent/ConcurrentMapCache.java +++ b/spring-context/src/main/java/org/springframework/cache/concurrent/ConcurrentMapCache.java @@ -25,6 +25,7 @@ import java.util.concurrent.ConcurrentMap; import org.springframework.cache.support.AbstractValueAdaptingCache; import org.springframework.core.serializer.support.SerializationDelegate; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -98,7 +99,7 @@ public class ConcurrentMapCache extends AbstractValueAdaptingCache { * @since 4.3 */ protected ConcurrentMapCache(String name, ConcurrentMap store, - boolean allowNullValues, SerializationDelegate serialization) { + boolean allowNullValues, @Nullable SerializationDelegate serialization) { super(allowNullValues); Assert.notNull(name, "Name must not be null"); diff --git a/spring-context/src/main/java/org/springframework/cache/concurrent/ConcurrentMapCacheManager.java b/spring-context/src/main/java/org/springframework/cache/concurrent/ConcurrentMapCacheManager.java index ad33fc4c87..781448b7c9 100644 --- a/spring-context/src/main/java/org/springframework/cache/concurrent/ConcurrentMapCacheManager.java +++ b/spring-context/src/main/java/org/springframework/cache/concurrent/ConcurrentMapCacheManager.java @@ -27,6 +27,7 @@ import org.springframework.beans.factory.BeanClassLoaderAware; import org.springframework.cache.Cache; import org.springframework.cache.CacheManager; import org.springframework.core.serializer.support.SerializationDelegate; +import org.springframework.lang.Nullable; /** * {@link CacheManager} implementation that lazily builds {@link ConcurrentMapCache} @@ -81,7 +82,7 @@ public class ConcurrentMapCacheManager implements CacheManager, BeanClassLoaderA *

Calling this with a {@code null} collection argument resets the * mode to 'dynamic', allowing for further creation of caches again. */ - public void setCacheNames(Collection cacheNames) { + public void setCacheNames(@Nullable Collection cacheNames) { if (cacheNames != null) { for (String name : cacheNames) { this.cacheMap.put(name, createConcurrentMapCache(name)); diff --git a/spring-context/src/main/java/org/springframework/cache/concurrent/package-info.java b/spring-context/src/main/java/org/springframework/cache/concurrent/package-info.java index 40cf65d313..d2e7d514bb 100644 --- a/spring-context/src/main/java/org/springframework/cache/concurrent/package-info.java +++ b/spring-context/src/main/java/org/springframework/cache/concurrent/package-info.java @@ -4,4 +4,7 @@ * and {@link org.springframework.cache.Cache Cache} implementation for * use in a Spring context, using a JDK based thread pool at runtime. */ +@NonNullApi package org.springframework.cache.concurrent; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context/src/main/java/org/springframework/cache/config/CacheAdviceParser.java b/spring-context/src/main/java/org/springframework/cache/config/CacheAdviceParser.java index b8864b7005..8503fcc690 100644 --- a/spring-context/src/main/java/org/springframework/cache/config/CacheAdviceParser.java +++ b/spring-context/src/main/java/org/springframework/cache/config/CacheAdviceParser.java @@ -36,6 +36,7 @@ import org.springframework.cache.interceptor.CacheOperation; import org.springframework.cache.interceptor.CachePutOperation; import org.springframework.cache.interceptor.CacheableOperation; import org.springframework.cache.interceptor.NameMatchCacheOperationSource; +import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; import org.springframework.util.xml.DomUtils; @@ -241,6 +242,7 @@ class CacheAdviceParser extends AbstractSingleBeanDefinitionParser { return builder; } + @Nullable String merge(Element element, ReaderContext readerCtx) { String method = element.getAttribute(METHOD_ATTRIBUTE); if (StringUtils.hasText(method)) { diff --git a/spring-context/src/main/java/org/springframework/cache/config/package-info.java b/spring-context/src/main/java/org/springframework/cache/config/package-info.java index f2533d3146..9d1e1f37f4 100644 --- a/spring-context/src/main/java/org/springframework/cache/config/package-info.java +++ b/spring-context/src/main/java/org/springframework/cache/config/package-info.java @@ -4,4 +4,7 @@ * org.springframework.cache.annotation.EnableCaching EnableCaching} * for details on code-based configuration without XML. */ +@NonNullApi package org.springframework.cache.config; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context/src/main/java/org/springframework/cache/interceptor/AbstractCacheInvoker.java b/spring-context/src/main/java/org/springframework/cache/interceptor/AbstractCacheInvoker.java index 81edc06703..7a793df984 100644 --- a/spring-context/src/main/java/org/springframework/cache/interceptor/AbstractCacheInvoker.java +++ b/spring-context/src/main/java/org/springframework/cache/interceptor/AbstractCacheInvoker.java @@ -17,6 +17,7 @@ package org.springframework.cache.interceptor; import org.springframework.cache.Cache; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -66,6 +67,7 @@ public abstract class AbstractCacheInvoker { * miss in case of error. * @see Cache#get(Object) */ + @Nullable protected Cache.ValueWrapper doGet(Cache cache, Object key) { try { return cache.get(key); diff --git a/spring-context/src/main/java/org/springframework/cache/interceptor/AbstractCacheResolver.java b/spring-context/src/main/java/org/springframework/cache/interceptor/AbstractCacheResolver.java index 3f018f46b6..e54fe17eab 100644 --- a/spring-context/src/main/java/org/springframework/cache/interceptor/AbstractCacheResolver.java +++ b/spring-context/src/main/java/org/springframework/cache/interceptor/AbstractCacheResolver.java @@ -23,6 +23,7 @@ import java.util.Collections; import org.springframework.beans.factory.InitializingBean; import org.springframework.cache.Cache; import org.springframework.cache.CacheManager; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -93,6 +94,7 @@ public abstract class AbstractCacheResolver implements CacheResolver, Initializi * @param context the context of the particular invocation * @return the cache name(s) to resolve or {@code null} if no cache should be resolved */ + @Nullable protected abstract Collection getCacheNames(CacheOperationInvocationContext context); } diff --git a/spring-context/src/main/java/org/springframework/cache/interceptor/AbstractFallbackCacheOperationSource.java b/spring-context/src/main/java/org/springframework/cache/interceptor/AbstractFallbackCacheOperationSource.java index 886aa94004..2a7fe44356 100644 --- a/spring-context/src/main/java/org/springframework/cache/interceptor/AbstractFallbackCacheOperationSource.java +++ b/spring-context/src/main/java/org/springframework/cache/interceptor/AbstractFallbackCacheOperationSource.java @@ -28,6 +28,7 @@ import org.apache.commons.logging.LogFactory; import org.springframework.core.BridgeMethodResolver; import org.springframework.core.MethodClassKey; +import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; /** @@ -116,10 +117,11 @@ public abstract class AbstractFallbackCacheOperationSource implements CacheOpera * @param targetClass the target class (may be {@code null}) * @return the cache key (never {@code null}) */ - protected Object getCacheKey(Method method, Class targetClass) { + protected Object getCacheKey(Method method, @Nullable Class targetClass) { return new MethodClassKey(method, targetClass); } + @Nullable private Collection computeCacheOperations(Method method, Class targetClass) { // Don't allow no-public methods as required. if (allowPublicMethodsOnly() && !Modifier.isPublic(method.getModifiers())) { @@ -168,6 +170,7 @@ public abstract class AbstractFallbackCacheOperationSource implements CacheOpera * @return all caching attribute associated with this method * (or {@code null} if none) */ + @Nullable protected abstract Collection findCacheOperations(Method method); /** @@ -177,6 +180,7 @@ public abstract class AbstractFallbackCacheOperationSource implements CacheOpera * @return all caching attribute associated with this class * (or {@code null} if none) */ + @Nullable protected abstract Collection findCacheOperations(Class clazz); /** diff --git a/spring-context/src/main/java/org/springframework/cache/interceptor/CacheAspectSupport.java b/spring-context/src/main/java/org/springframework/cache/interceptor/CacheAspectSupport.java index 1e03becc11..e69e141f4d 100644 --- a/spring-context/src/main/java/org/springframework/cache/interceptor/CacheAspectSupport.java +++ b/spring-context/src/main/java/org/springframework/cache/interceptor/CacheAspectSupport.java @@ -42,6 +42,7 @@ import org.springframework.cache.Cache; import org.springframework.cache.CacheManager; import org.springframework.context.expression.AnnotatedElementKey; import org.springframework.expression.EvaluationContext; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.CollectionUtils; @@ -470,6 +471,7 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker * @return a {@link Cache.ValueWrapper} holding the cached item, * or {@code null} if none is found */ + @Nullable private Cache.ValueWrapper findCachedItem(Collection contexts) { Object result = CacheOperationExpressionEvaluator.NO_RESULT; for (CacheOperationContext context : contexts) { @@ -507,6 +509,7 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker } } + @Nullable private Cache.ValueWrapper findInCaches(CacheOperationContext context, Object key) { for (Cache cache : context.getCaches()) { Cache.ValueWrapper wrapper = doGet(cache, key); @@ -711,6 +714,7 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker * Compute the key for the given caching operation. * @return the generated key, or {@code null} if none can be generated */ + @Nullable protected Object generateKey(Object result) { if (StringUtils.hasText(this.metadata.operation.getKey())) { EvaluationContext evaluationContext = createEvaluationContext(result); diff --git a/spring-context/src/main/java/org/springframework/cache/interceptor/CacheOperationExpressionEvaluator.java b/spring-context/src/main/java/org/springframework/cache/interceptor/CacheOperationExpressionEvaluator.java index 0e3de59b5b..58fb2db42b 100644 --- a/spring-context/src/main/java/org/springframework/cache/interceptor/CacheOperationExpressionEvaluator.java +++ b/spring-context/src/main/java/org/springframework/cache/interceptor/CacheOperationExpressionEvaluator.java @@ -29,6 +29,7 @@ import org.springframework.context.expression.BeanFactoryResolver; import org.springframework.context.expression.CachedExpressionEvaluator; import org.springframework.expression.EvaluationContext; import org.springframework.expression.Expression; +import org.springframework.lang.Nullable; /** * Utility class handling the SpEL expression parsing. @@ -93,7 +94,7 @@ class CacheOperationExpressionEvaluator extends CachedExpressionEvaluator { * @return the evaluation context */ public EvaluationContext createEvaluationContext(Collection caches, - Method method, Object[] args, Object target, Class targetClass, Object result, + Method method, Object[] args, Object target, Class targetClass, @Nullable Object result, BeanFactory beanFactory) { CacheExpressionRootObject rootObject = new CacheExpressionRootObject( diff --git a/spring-context/src/main/java/org/springframework/cache/interceptor/CacheOperationSource.java b/spring-context/src/main/java/org/springframework/cache/interceptor/CacheOperationSource.java index 376d2a1647..0ab1059325 100644 --- a/spring-context/src/main/java/org/springframework/cache/interceptor/CacheOperationSource.java +++ b/spring-context/src/main/java/org/springframework/cache/interceptor/CacheOperationSource.java @@ -19,6 +19,8 @@ package org.springframework.cache.interceptor; import java.lang.reflect.Method; import java.util.Collection; +import org.springframework.lang.Nullable; + /** * Interface used by {@link CacheInterceptor}. Implementations know how to source * cache operation attributes, whether from configuration, metadata attributes at @@ -37,6 +39,7 @@ public interface CacheOperationSource { * the declaring class of the method must be used) * @return all cache operations for this method, or {@code null} if none found */ - Collection getCacheOperations(Method method, Class targetClass); + @Nullable + Collection getCacheOperations(Method method, @Nullable Class targetClass); } diff --git a/spring-context/src/main/java/org/springframework/cache/interceptor/CacheOperationSourcePointcut.java b/spring-context/src/main/java/org/springframework/cache/interceptor/CacheOperationSourcePointcut.java index 58548bb799..6a245b055b 100644 --- a/spring-context/src/main/java/org/springframework/cache/interceptor/CacheOperationSourcePointcut.java +++ b/spring-context/src/main/java/org/springframework/cache/interceptor/CacheOperationSourcePointcut.java @@ -20,6 +20,7 @@ import java.io.Serializable; import java.lang.reflect.Method; import org.springframework.aop.support.StaticMethodMatcherPointcut; +import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; import org.springframework.util.ObjectUtils; @@ -66,6 +67,7 @@ abstract class CacheOperationSourcePointcut extends StaticMethodMatcherPointcut * Obtain the underlying {@link CacheOperationSource} (may be {@code null}). * To be implemented by subclasses. */ + @Nullable protected abstract CacheOperationSource getCacheOperationSource(); } diff --git a/spring-context/src/main/java/org/springframework/cache/interceptor/package-info.java b/spring-context/src/main/java/org/springframework/cache/interceptor/package-info.java index 943130ebfe..cce2ac4f34 100644 --- a/spring-context/src/main/java/org/springframework/cache/interceptor/package-info.java +++ b/spring-context/src/main/java/org/springframework/cache/interceptor/package-info.java @@ -3,4 +3,7 @@ * Builds on the AOP infrastructure in org.springframework.aop.framework. * Any POJO can be cache-advised with Spring. */ +@NonNullApi package org.springframework.cache.interceptor; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context/src/main/java/org/springframework/cache/package-info.java b/spring-context/src/main/java/org/springframework/cache/package-info.java index 982312e824..3944cf0ce1 100644 --- a/spring-context/src/main/java/org/springframework/cache/package-info.java +++ b/spring-context/src/main/java/org/springframework/cache/package-info.java @@ -2,4 +2,7 @@ * Spring's generic cache abstraction. * Concrete implementations are provided in the subpackages. */ +@NonNullApi package org.springframework.cache; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context/src/main/java/org/springframework/cache/support/AbstractCacheManager.java b/spring-context/src/main/java/org/springframework/cache/support/AbstractCacheManager.java index a05aa254a4..7acb7deb1b 100644 --- a/spring-context/src/main/java/org/springframework/cache/support/AbstractCacheManager.java +++ b/spring-context/src/main/java/org/springframework/cache/support/AbstractCacheManager.java @@ -26,6 +26,7 @@ import java.util.concurrent.ConcurrentMap; import org.springframework.beans.factory.InitializingBean; import org.springframework.cache.Cache; import org.springframework.cache.CacheManager; +import org.springframework.lang.Nullable; /** * Abstract base class implementing the common {@link CacheManager} methods. @@ -124,6 +125,7 @@ public abstract class AbstractCacheManager implements CacheManager, Initializing * @see #getCache(String) * @see #getMissingCache(String) */ + @Nullable protected final Cache lookupCache(String name) { return this.cacheMap.get(name); } @@ -183,6 +185,7 @@ public abstract class AbstractCacheManager implements CacheManager, Initializing * @since 4.1 * @see #getCache(String) */ + @Nullable protected Cache getMissingCache(String name) { return null; } diff --git a/spring-context/src/main/java/org/springframework/cache/support/AbstractValueAdaptingCache.java b/spring-context/src/main/java/org/springframework/cache/support/AbstractValueAdaptingCache.java index a197831c5e..d70b9ed94a 100644 --- a/spring-context/src/main/java/org/springframework/cache/support/AbstractValueAdaptingCache.java +++ b/spring-context/src/main/java/org/springframework/cache/support/AbstractValueAdaptingCache.java @@ -17,6 +17,7 @@ package org.springframework.cache.support; import org.springframework.cache.Cache; +import org.springframework.lang.Nullable; /** * Common base class for {@link Cache} implementations that need to adapt @@ -81,7 +82,8 @@ public abstract class AbstractValueAdaptingCache implements Cache { * @param storeValue the store value * @return the value to return to the user */ - protected Object fromStoreValue(Object storeValue) { + @Nullable + protected Object fromStoreValue(@Nullable Object storeValue) { if (this.allowNullValues && storeValue == NullValue.INSTANCE) { return null; } @@ -94,7 +96,7 @@ public abstract class AbstractValueAdaptingCache implements Cache { * @param userValue the given user value * @return the value to store */ - protected Object toStoreValue(Object userValue) { + protected Object toStoreValue(@Nullable Object userValue) { if (userValue == null) { if (this.allowNullValues) { return NullValue.INSTANCE; diff --git a/spring-context/src/main/java/org/springframework/cache/support/SimpleValueWrapper.java b/spring-context/src/main/java/org/springframework/cache/support/SimpleValueWrapper.java index b248902038..3c94d081a3 100644 --- a/spring-context/src/main/java/org/springframework/cache/support/SimpleValueWrapper.java +++ b/spring-context/src/main/java/org/springframework/cache/support/SimpleValueWrapper.java @@ -17,6 +17,7 @@ package org.springframework.cache.support; import org.springframework.cache.Cache.ValueWrapper; +import org.springframework.lang.Nullable; /** * Straightforward implementation of {@link org.springframework.cache.Cache.ValueWrapper}, @@ -34,7 +35,7 @@ public class SimpleValueWrapper implements ValueWrapper { * Create a new SimpleValueWrapper instance for exposing the given value. * @param value the value to expose (may be {@code null}) */ - public SimpleValueWrapper(Object value) { + public SimpleValueWrapper(@Nullable Object value) { this.value = value; } diff --git a/spring-context/src/main/java/org/springframework/cache/support/package-info.java b/spring-context/src/main/java/org/springframework/cache/support/package-info.java index cf3f5d4f29..6be9db7ef0 100644 --- a/spring-context/src/main/java/org/springframework/cache/support/package-info.java +++ b/spring-context/src/main/java/org/springframework/cache/support/package-info.java @@ -2,4 +2,7 @@ * Support classes for the org.springframework.cache package. * Provides abstract classes for cache managers and caches. */ +@NonNullApi package org.springframework.cache.support; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context/src/main/java/org/springframework/context/ApplicationContext.java b/spring-context/src/main/java/org/springframework/context/ApplicationContext.java index c68f01265e..2982f9ab12 100644 --- a/spring-context/src/main/java/org/springframework/context/ApplicationContext.java +++ b/spring-context/src/main/java/org/springframework/context/ApplicationContext.java @@ -21,6 +21,7 @@ import org.springframework.beans.factory.ListableBeanFactory; import org.springframework.beans.factory.config.AutowireCapableBeanFactory; import org.springframework.core.env.EnvironmentCapable; import org.springframework.core.io.support.ResourcePatternResolver; +import org.springframework.lang.Nullable; /** * Central interface to provide configuration for an application. @@ -61,6 +62,7 @@ public interface ApplicationContext extends EnvironmentCapable, ListableBeanFact * Return the unique id of this application context. * @return the unique id of the context, or {@code null} if none */ + @Nullable String getId(); /** @@ -86,6 +88,7 @@ public interface ApplicationContext extends EnvironmentCapable, ListableBeanFact * and this is the root of the context hierarchy. * @return the parent context, or {@code null} if there is no parent */ + @Nullable ApplicationContext getParent(); /** diff --git a/spring-context/src/main/java/org/springframework/context/ConfigurableApplicationContext.java b/spring-context/src/main/java/org/springframework/context/ConfigurableApplicationContext.java index 1f6ecc4196..0ffc57839c 100644 --- a/spring-context/src/main/java/org/springframework/context/ConfigurableApplicationContext.java +++ b/spring-context/src/main/java/org/springframework/context/ConfigurableApplicationContext.java @@ -24,6 +24,7 @@ import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.Environment; import org.springframework.core.io.ProtocolResolver; +import org.springframework.lang.Nullable; /** * SPI interface to be implemented by most if not all application contexts. @@ -100,7 +101,7 @@ public interface ConfigurableApplicationContext extends ApplicationContext, Life * @param parent the parent context * @see org.springframework.web.context.ConfigurableWebApplicationContext */ - void setParent(ApplicationContext parent); + void setParent(@Nullable ApplicationContext parent); /** * Set the {@code Environment} for this application context. diff --git a/spring-context/src/main/java/org/springframework/context/HierarchicalMessageSource.java b/spring-context/src/main/java/org/springframework/context/HierarchicalMessageSource.java index d03b98774d..c243387451 100644 --- a/spring-context/src/main/java/org/springframework/context/HierarchicalMessageSource.java +++ b/spring-context/src/main/java/org/springframework/context/HierarchicalMessageSource.java @@ -16,6 +16,8 @@ package org.springframework.context; +import org.springframework.lang.Nullable; + /** * Sub-interface of MessageSource to be implemented by objects that * can resolve messages hierarchically. @@ -32,11 +34,12 @@ public interface HierarchicalMessageSource extends MessageSource { * resolve messages that this object can't resolve. * May be {@code null}, in which case no further resolution is possible. */ - void setParentMessageSource(MessageSource parent); + void setParentMessageSource(@Nullable MessageSource parent); /** * Return the parent of this MessageSource, or {@code null} if none. */ + @Nullable MessageSource getParentMessageSource(); } diff --git a/spring-context/src/main/java/org/springframework/context/MessageSource.java b/spring-context/src/main/java/org/springframework/context/MessageSource.java index 1a4d0b40ef..27bac5068e 100644 --- a/spring-context/src/main/java/org/springframework/context/MessageSource.java +++ b/spring-context/src/main/java/org/springframework/context/MessageSource.java @@ -18,6 +18,8 @@ package org.springframework.context; import java.util.Locale; +import org.springframework.lang.Nullable; + /** * Strategy interface for resolving messages, with support for the parameterization * and internationalization of such messages. @@ -51,7 +53,7 @@ public interface MessageSource { * otherwise the default message passed as a parameter * @see java.text.MessageFormat */ - String getMessage(String code, Object[] args, String defaultMessage, Locale locale); + String getMessage(String code, @Nullable Object[] args, String defaultMessage, Locale locale); /** * Try to resolve the message. Treat as an error if the message can't be found. @@ -64,7 +66,7 @@ public interface MessageSource { * @throws NoSuchMessageException if the message wasn't found * @see java.text.MessageFormat */ - String getMessage(String code, Object[] args, Locale locale) throws NoSuchMessageException; + String getMessage(String code, @Nullable Object[] args, Locale locale) throws NoSuchMessageException; /** * Try to resolve the message using all the attributes contained within the diff --git a/spring-context/src/main/java/org/springframework/context/MessageSourceResolvable.java b/spring-context/src/main/java/org/springframework/context/MessageSourceResolvable.java index 3dca904f63..096e774d2a 100644 --- a/spring-context/src/main/java/org/springframework/context/MessageSourceResolvable.java +++ b/spring-context/src/main/java/org/springframework/context/MessageSourceResolvable.java @@ -16,6 +16,8 @@ package org.springframework.context; +import org.springframework.lang.Nullable; + /** * Interface for objects that are suitable for message resolution in a * {@link MessageSource}. @@ -44,6 +46,7 @@ public interface MessageSourceResolvable { * placeholders within the message text * @see java.text.MessageFormat */ + @Nullable default Object[] getArguments() { return null; } @@ -57,6 +60,7 @@ public interface MessageSourceResolvable { * for this particular message. * @return the default message, or {@code null} if no default */ + @Nullable default String getDefaultMessage() { return null; } diff --git a/spring-context/src/main/java/org/springframework/context/annotation/AdviceModeImportSelector.java b/spring-context/src/main/java/org/springframework/context/annotation/AdviceModeImportSelector.java index 14f9f1bfa2..adfb7a55de 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/AdviceModeImportSelector.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/AdviceModeImportSelector.java @@ -21,8 +21,9 @@ import java.lang.annotation.Annotation; import org.springframework.core.GenericTypeResolver; import org.springframework.core.annotation.AnnotationAttributes; import org.springframework.core.type.AnnotationMetadata; +import org.springframework.lang.Nullable; - /** +/** * Convenient base class for {@link ImportSelector} implementations that select imports * based on an {@link AdviceMode} value from an annotation (such as the {@code @Enable*} * annotations). @@ -85,6 +86,7 @@ public abstract class AdviceModeImportSelector implements * @return array containing classes to import; empty array if none, {@code null} if * the given {@code AdviceMode} is unknown. */ + @Nullable protected abstract String[] selectImports(AdviceMode adviceMode); } diff --git a/spring-context/src/main/java/org/springframework/context/annotation/AnnotatedBeanDefinitionReader.java b/spring-context/src/main/java/org/springframework/context/annotation/AnnotatedBeanDefinitionReader.java index e28f41d9d1..1b2101c765 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/AnnotatedBeanDefinitionReader.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/AnnotatedBeanDefinitionReader.java @@ -30,6 +30,7 @@ import org.springframework.beans.factory.support.BeanNameGenerator; import org.springframework.core.env.Environment; import org.springframework.core.env.EnvironmentCapable; import org.springframework.core.env.StandardEnvironment; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -153,7 +154,7 @@ public class AnnotatedBeanDefinitionReader { * (may be {@code null}) * @since 5.0 */ - public void registerBean(Class annotatedClass, Supplier instanceSupplier) { + public void registerBean(Class annotatedClass, @Nullable Supplier instanceSupplier) { doRegisterBean(annotatedClass, instanceSupplier, null, null); } @@ -167,7 +168,7 @@ public class AnnotatedBeanDefinitionReader { * (may be {@code null}) * @since 5.0 */ - public void registerBean(Class annotatedClass, String name, Supplier instanceSupplier) { + public void registerBean(Class annotatedClass, String name, @Nullable Supplier instanceSupplier) { doRegisterBean(annotatedClass, instanceSupplier, name, null); } @@ -209,8 +210,8 @@ public class AnnotatedBeanDefinitionReader { * factory's {@link BeanDefinition}, e.g. setting a lazy-init or primary flag * @since 5.0 */ - void doRegisterBean(Class annotatedClass, Supplier instanceSupplier, String name, - Class[] qualifiers, BeanDefinitionCustomizer... definitionCustomizers) { + void doRegisterBean(Class annotatedClass, @Nullable Supplier instanceSupplier, String name, + @Nullable Class[] qualifiers, BeanDefinitionCustomizer... definitionCustomizers) { AnnotatedGenericBeanDefinition abd = new AnnotatedGenericBeanDefinition(annotatedClass); if (this.conditionEvaluator.shouldSkip(abd.getMetadata())) { diff --git a/spring-context/src/main/java/org/springframework/context/annotation/AnnotationBeanNameGenerator.java b/spring-context/src/main/java/org/springframework/context/annotation/AnnotationBeanNameGenerator.java index dea7da17b7..8d4dd12103 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/AnnotationBeanNameGenerator.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/AnnotationBeanNameGenerator.java @@ -26,6 +26,7 @@ import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.beans.factory.support.BeanNameGenerator; import org.springframework.core.annotation.AnnotationAttributes; import org.springframework.core.type.AnnotationMetadata; +import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.util.StringUtils; @@ -82,6 +83,7 @@ public class AnnotationBeanNameGenerator implements BeanNameGenerator { * @param annotatedDef the annotation-aware bean definition * @return the bean name, or {@code null} if none is found */ + @Nullable protected String determineBeanNameFromAnnotation(AnnotatedBeanDefinition annotatedDef) { AnnotationMetadata amd = annotatedDef.getMetadata(); Set types = amd.getAnnotationTypes(); @@ -131,6 +133,7 @@ public class AnnotationBeanNameGenerator implements BeanNameGenerator { * @param registry the registry that the given bean definition is being registered with * @return the default bean name (never {@code null}) */ + @Nullable protected String buildDefaultBeanName(BeanDefinition definition, BeanDefinitionRegistry registry) { return buildDefaultBeanName(definition); } @@ -145,6 +148,7 @@ public class AnnotationBeanNameGenerator implements BeanNameGenerator { * @param definition the bean definition to build a bean name for * @return the default bean name (never {@code null}) */ + @Nullable protected String buildDefaultBeanName(BeanDefinition definition) { String shortClassName = ClassUtils.getShortName(definition.getBeanClassName()); return Introspector.decapitalize(shortClassName); diff --git a/spring-context/src/main/java/org/springframework/context/annotation/AnnotationConfigApplicationContext.java b/spring-context/src/main/java/org/springframework/context/annotation/AnnotationConfigApplicationContext.java index 61957aec47..1f67a31a58 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/AnnotationConfigApplicationContext.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/AnnotationConfigApplicationContext.java @@ -23,6 +23,7 @@ import org.springframework.beans.factory.support.BeanNameGenerator; import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.context.support.GenericApplicationContext; import org.springframework.core.env.ConfigurableEnvironment; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -187,7 +188,7 @@ public class AnnotationConfigApplicationContext extends GenericApplicationContex * (may be {@code null} or empty) * @since 5.0 */ - public void registerBean(Class annotatedClass, Object... constructorArguments) { + public void registerBean(Class annotatedClass, @Nullable Object... constructorArguments) { registerBean(null, annotatedClass, constructorArguments); } @@ -203,7 +204,7 @@ public class AnnotationConfigApplicationContext extends GenericApplicationContex * (may be {@code null} or empty) * @since 5.0 */ - public void registerBean(String beanName, Class annotatedClass, Object... constructorArguments) { + public void registerBean(@Nullable String beanName, Class annotatedClass, @Nullable Object... constructorArguments) { this.reader.doRegisterBean(annotatedClass, null, beanName, null, bd -> { for (Object arg : constructorArguments) { diff --git a/spring-context/src/main/java/org/springframework/context/annotation/AnnotationConfigUtils.java b/spring-context/src/main/java/org/springframework/context/annotation/AnnotationConfigUtils.java index a897652984..9f688c893a 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/AnnotationConfigUtils.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/AnnotationConfigUtils.java @@ -37,6 +37,7 @@ import org.springframework.core.annotation.AnnotationAttributes; import org.springframework.core.annotation.AnnotationAwareOrderComparator; import org.springframework.core.type.AnnotatedTypeMetadata; import org.springframework.core.type.AnnotationMetadata; +import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; /** @@ -143,7 +144,7 @@ public class AnnotationConfigUtils { * that have actually been registered by this call */ public static Set registerAnnotationConfigProcessors( - BeanDefinitionRegistry registry, Object source) { + BeanDefinitionRegistry registry, @Nullable Object source) { DefaultListableBeanFactory beanFactory = unwrapDefaultListableBeanFactory(registry); if (beanFactory != null) { @@ -219,6 +220,7 @@ public class AnnotationConfigUtils { return new BeanDefinitionHolder(definition, beanName); } + @Nullable private static DefaultListableBeanFactory unwrapDefaultListableBeanFactory(BeanDefinitionRegistry registry) { if (registry instanceof DefaultListableBeanFactory) { return (DefaultListableBeanFactory) registry; diff --git a/spring-context/src/main/java/org/springframework/context/annotation/ClassPathScanningCandidateComponentProvider.java b/spring-context/src/main/java/org/springframework/context/annotation/ClassPathScanningCandidateComponentProvider.java index f6aa75deff..fb182667f5 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/ClassPathScanningCandidateComponentProvider.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/ClassPathScanningCandidateComponentProvider.java @@ -51,6 +51,7 @@ import org.springframework.core.type.classreading.MetadataReaderFactory; import org.springframework.core.type.filter.AnnotationTypeFilter; import org.springframework.core.type.filter.AssignableTypeFilter; import org.springframework.core.type.filter.TypeFilter; +import org.springframework.lang.Nullable; import org.springframework.stereotype.Component; import org.springframework.stereotype.Controller; import org.springframework.stereotype.Indexed; @@ -237,6 +238,7 @@ public class ClassPathScanningCandidateComponentProvider implements EnvironmentC /** * Return the {@link BeanDefinitionRegistry} used by this scanner, if any. */ + @Nullable protected BeanDefinitionRegistry getRegistry() { return null; } @@ -341,6 +343,7 @@ public class ClassPathScanningCandidateComponentProvider implements EnvironmentC * @since 5.0 * @see #isIndexSupportsIncludeFilter(TypeFilter) */ + @Nullable protected String extractStereotype(TypeFilter filter) { if (filter instanceof AnnotationTypeFilter) { return ((AnnotationTypeFilter) filter).getAnnotationType().getName(); diff --git a/spring-context/src/main/java/org/springframework/context/annotation/ConditionContext.java b/spring-context/src/main/java/org/springframework/context/annotation/ConditionContext.java index 8be2dad829..4eb3a847ca 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/ConditionContext.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/ConditionContext.java @@ -20,6 +20,7 @@ import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.core.env.Environment; import org.springframework.core.io.ResourceLoader; +import org.springframework.lang.Nullable; /** * Context information for use by {@link Condition}s. @@ -34,6 +35,7 @@ public interface ConditionContext { * should the condition match or {@code null} if the registry is not available. * @return the registry or {@code null} */ + @Nullable BeanDefinitionRegistry getRegistry(); /** @@ -42,6 +44,7 @@ public interface ConditionContext { * is not available. * @return the bean factory or {@code null} */ + @Nullable ConfigurableListableBeanFactory getBeanFactory(); /** @@ -49,6 +52,7 @@ public interface ConditionContext { * or {@code null} if no environment is available. * @return the environment or {@code null} */ + @Nullable Environment getEnvironment(); /** @@ -56,6 +60,7 @@ public interface ConditionContext { * if the resource loader cannot be obtained. * @return a resource loader or {@code null} */ + @Nullable ResourceLoader getResourceLoader(); /** @@ -63,6 +68,7 @@ public interface ConditionContext { * classes or {@code null} if the default classloader should be used. * @return the class loader or {@code null} */ + @Nullable ClassLoader getClassLoader(); } diff --git a/spring-context/src/main/java/org/springframework/context/annotation/ConditionEvaluator.java b/spring-context/src/main/java/org/springframework/context/annotation/ConditionEvaluator.java index 617a045652..7f085e101b 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/ConditionEvaluator.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/ConditionEvaluator.java @@ -31,6 +31,7 @@ import org.springframework.core.env.EnvironmentCapable; import org.springframework.core.io.ResourceLoader; import org.springframework.core.type.AnnotatedTypeMetadata; import org.springframework.core.type.AnnotationMetadata; +import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.util.MultiValueMap; @@ -141,6 +142,7 @@ class ConditionEvaluator { this.resourceLoader = (resourceLoader != null ? resourceLoader : deduceResourceLoader(registry)); } + @Nullable private ConfigurableListableBeanFactory deduceBeanFactory(BeanDefinitionRegistry source) { if (source instanceof ConfigurableListableBeanFactory) { return (ConfigurableListableBeanFactory) source; @@ -151,6 +153,7 @@ class ConditionEvaluator { return null; } + @Nullable private Environment deduceEnvironment(BeanDefinitionRegistry source) { if (source instanceof EnvironmentCapable) { return ((EnvironmentCapable) source).getEnvironment(); @@ -158,6 +161,7 @@ class ConditionEvaluator { return null; } + @Nullable private ResourceLoader deduceResourceLoader(BeanDefinitionRegistry source) { if (source instanceof ResourceLoader) { return (ResourceLoader) source; diff --git a/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClass.java b/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClass.java index 5802c69b51..5cc0dccc25 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClass.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClass.java @@ -31,6 +31,7 @@ import org.springframework.core.io.Resource; import org.springframework.core.type.AnnotationMetadata; import org.springframework.core.type.StandardAnnotationMetadata; import org.springframework.core.type.classreading.MetadataReader; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; @@ -88,7 +89,7 @@ final class ConfigurationClass { * @param importedBy the configuration class importing this one or {@code null} * @since 3.1.1 */ - public ConfigurationClass(MetadataReader metadataReader, ConfigurationClass importedBy) { + public ConfigurationClass(MetadataReader metadataReader, @Nullable ConfigurationClass importedBy) { this.metadata = metadataReader.getAnnotationMetadata(); this.resource = metadataReader.getResource(); this.importedBy.add(importedBy); @@ -115,7 +116,7 @@ final class ConfigurationClass { * @param importedBy the configuration class importing this one or {@code null} * @since 3.1.1 */ - public ConfigurationClass(Class clazz, ConfigurationClass importedBy) { + public ConfigurationClass(Class clazz, @Nullable ConfigurationClass importedBy) { this.metadata = new StandardAnnotationMetadata(clazz, true); this.resource = new DescriptiveResource(clazz.getName()); this.importedBy.add(importedBy); diff --git a/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassEnhancer.java b/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassEnhancer.java index 192a8eabab..cd4881f37f 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassEnhancer.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassEnhancer.java @@ -49,6 +49,7 @@ import org.springframework.cglib.proxy.NoOp; import org.springframework.cglib.transform.ClassEmitterTransformer; import org.springframework.cglib.transform.TransformingClassGenerator; import org.springframework.core.annotation.AnnotatedElementUtils; +import org.springframework.lang.Nullable; import org.springframework.objenesis.ObjenesisException; import org.springframework.objenesis.SpringObjenesis; import org.springframework.util.Assert; @@ -269,6 +270,7 @@ class ConfigurationClassEnhancer { private static class BeanFactoryAwareMethodInterceptor implements MethodInterceptor, ConditionalCallback { @Override + @Nullable public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable { Field field = ReflectionUtils.findField(obj.getClass(), BEAN_FACTORY_FIELD); Assert.state(field != null, "Unable to find generated BeanFactory field"); diff --git a/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java b/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java index 165a801be1..e6c1c3d368 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java @@ -72,6 +72,7 @@ import org.springframework.core.type.StandardAnnotationMetadata; import org.springframework.core.type.classreading.MetadataReader; import org.springframework.core.type.classreading.MetadataReaderFactory; import org.springframework.core.type.filter.AssignableTypeFilter; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.util.LinkedMultiValueMap; @@ -258,6 +259,7 @@ class ConfigurationClassParser { * @param sourceClass a source class * @return the superclass, or {@code null} if none found or previously processed */ + @Nullable protected final SourceClass doProcessConfigurationClass(ConfigurationClass configClass, SourceClass sourceClass) throws IOException { diff --git a/spring-context/src/main/java/org/springframework/context/annotation/MBeanExportConfiguration.java b/spring-context/src/main/java/org/springframework/context/annotation/MBeanExportConfiguration.java index b934db9403..0e4a841041 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/MBeanExportConfiguration.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/MBeanExportConfiguration.java @@ -32,6 +32,7 @@ import org.springframework.jmx.export.annotation.AnnotationMBeanExporter; import org.springframework.jmx.support.RegistrationPolicy; import org.springframework.jmx.support.WebSphereMBeanServerFactoryBean; import org.springframework.jndi.JndiLocatorDelegate; +import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.util.StringUtils; @@ -152,6 +153,7 @@ public class MBeanExportConfiguration implements ImportAware, EnvironmentAware, public abstract MBeanServer getMBeanServer(); + @Nullable public static SpecificPlatform get() { ClassLoader classLoader = MBeanExportConfiguration.class.getClassLoader(); for (SpecificPlatform environment : values()) { diff --git a/spring-context/src/main/java/org/springframework/context/annotation/package-info.java b/spring-context/src/main/java/org/springframework/context/annotation/package-info.java index 590924e7d4..ca7cc4691b 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/package-info.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/package-info.java @@ -3,4 +3,7 @@ * annotations, component-scanning, and Java-based metadata for creating * Spring-managed objects. */ +@NonNullApi package org.springframework.context.annotation; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context/src/main/java/org/springframework/context/config/MBeanServerBeanDefinitionParser.java b/spring-context/src/main/java/org/springframework/context/config/MBeanServerBeanDefinitionParser.java index 2557ab6afb..f9dc36848c 100644 --- a/spring-context/src/main/java/org/springframework/context/config/MBeanServerBeanDefinitionParser.java +++ b/spring-context/src/main/java/org/springframework/context/config/MBeanServerBeanDefinitionParser.java @@ -26,6 +26,7 @@ import org.springframework.beans.factory.xml.ParserContext; import org.springframework.jmx.support.MBeanServerFactoryBean; import org.springframework.jmx.support.WebSphereMBeanServerFactoryBean; import org.springframework.jndi.JndiObjectFactoryBean; +import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.util.StringUtils; @@ -82,6 +83,7 @@ class MBeanServerBeanDefinitionParser extends AbstractBeanDefinitionParser { return bd; } + @Nullable static AbstractBeanDefinition findServerForSpecialEnvironment() { if (weblogicPresent) { RootBeanDefinition bd = new RootBeanDefinition(JndiObjectFactoryBean.class); diff --git a/spring-context/src/main/java/org/springframework/context/config/package-info.java b/spring-context/src/main/java/org/springframework/context/config/package-info.java index 872af52b88..cb5eea6b56 100644 --- a/spring-context/src/main/java/org/springframework/context/config/package-info.java +++ b/spring-context/src/main/java/org/springframework/context/config/package-info.java @@ -2,4 +2,7 @@ * Support package for advanced application context configuration, * with XML schema being the primary configuration format. */ +@NonNullApi package org.springframework.context.config; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context/src/main/java/org/springframework/context/event/ApplicationEventMulticaster.java b/spring-context/src/main/java/org/springframework/context/event/ApplicationEventMulticaster.java index e00601d243..f5a71053df 100644 --- a/spring-context/src/main/java/org/springframework/context/event/ApplicationEventMulticaster.java +++ b/spring-context/src/main/java/org/springframework/context/event/ApplicationEventMulticaster.java @@ -19,6 +19,7 @@ package org.springframework.context.event; import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationListener; import org.springframework.core.ResolvableType; +import org.springframework.lang.Nullable; /** * Interface to be implemented by objects that can manage a number of @@ -81,6 +82,6 @@ public interface ApplicationEventMulticaster { * @param eventType the type of event (can be null) * @since 4.2 */ - void multicastEvent(ApplicationEvent event, ResolvableType eventType); + void multicastEvent(ApplicationEvent event, @Nullable ResolvableType eventType); } diff --git a/spring-context/src/main/java/org/springframework/context/event/ApplicationListenerMethodAdapter.java b/spring-context/src/main/java/org/springframework/context/event/ApplicationListenerMethodAdapter.java index 4bb3088fdf..3db1c2a5f4 100644 --- a/spring-context/src/main/java/org/springframework/context/event/ApplicationListenerMethodAdapter.java +++ b/spring-context/src/main/java/org/springframework/context/event/ApplicationListenerMethodAdapter.java @@ -36,6 +36,7 @@ import org.springframework.core.ResolvableType; import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.core.annotation.Order; import org.springframework.expression.EvaluationContext; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; import org.springframework.util.ReflectionUtils; @@ -187,6 +188,7 @@ public class ApplicationListenerMethodAdapter implements GenericApplicationListe * return {@code null} to indicate that no suitable arguments could be resolved and * therefore the method should not be invoked at all for the specified event. */ + @Nullable protected Object[] resolveArguments(ApplicationEvent event) { ResolvableType declaredEventType = getResolvableType(event); if (declaredEventType == null) { @@ -338,7 +340,7 @@ public class ApplicationListenerMethodAdapter implements GenericApplicationListe return sb.toString(); } - + @Nullable private ResolvableType getResolvableType(ApplicationEvent event) { ResolvableType payloadType = null; if (event instanceof PayloadApplicationEvent) { diff --git a/spring-context/src/main/java/org/springframework/context/event/GenericApplicationListenerAdapter.java b/spring-context/src/main/java/org/springframework/context/event/GenericApplicationListenerAdapter.java index 7f27f1c602..1af2b407de 100644 --- a/spring-context/src/main/java/org/springframework/context/event/GenericApplicationListenerAdapter.java +++ b/spring-context/src/main/java/org/springframework/context/event/GenericApplicationListenerAdapter.java @@ -21,6 +21,7 @@ import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationListener; import org.springframework.core.Ordered; import org.springframework.core.ResolvableType; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -88,7 +89,7 @@ public class GenericApplicationListenerAdapter implements GenericApplicationList return (this.delegate instanceof Ordered ? ((Ordered) this.delegate).getOrder() : Ordered.LOWEST_PRECEDENCE); } - + @Nullable static ResolvableType resolveDeclaredEventType(Class listenerType) { ResolvableType resolvableType = ResolvableType.forClass(listenerType).as(ApplicationListener.class); if (resolvableType == null || !resolvableType.hasGenerics()) { diff --git a/spring-context/src/main/java/org/springframework/context/event/package-info.java b/spring-context/src/main/java/org/springframework/context/event/package-info.java index d4dcbaa694..b364750977 100644 --- a/spring-context/src/main/java/org/springframework/context/event/package-info.java +++ b/spring-context/src/main/java/org/springframework/context/event/package-info.java @@ -2,4 +2,7 @@ * Support classes for application events, like standard context events. * To be supported by all major application context implementations. */ +@NonNullApi package org.springframework.context.event; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context/src/main/java/org/springframework/context/expression/package-info.java b/spring-context/src/main/java/org/springframework/context/expression/package-info.java index cb8b9b2db6..37e662a876 100644 --- a/spring-context/src/main/java/org/springframework/context/expression/package-info.java +++ b/spring-context/src/main/java/org/springframework/context/expression/package-info.java @@ -1,4 +1,7 @@ /** * Expression parsing support within a Spring application context. */ +@NonNullApi package org.springframework.context.expression; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context/src/main/java/org/springframework/context/i18n/LocaleContext.java b/spring-context/src/main/java/org/springframework/context/i18n/LocaleContext.java index 6ac813b527..001956ffac 100644 --- a/spring-context/src/main/java/org/springframework/context/i18n/LocaleContext.java +++ b/spring-context/src/main/java/org/springframework/context/i18n/LocaleContext.java @@ -18,6 +18,8 @@ package org.springframework.context.i18n; import java.util.Locale; +import org.springframework.lang.Nullable; + /** * Strategy interface for determining the current Locale. * @@ -36,6 +38,7 @@ public interface LocaleContext { * depending on the implementation strategy. * @return the current Locale, or {@code null} if no specific Locale associated */ + @Nullable Locale getLocale(); } diff --git a/spring-context/src/main/java/org/springframework/context/i18n/LocaleContextHolder.java b/spring-context/src/main/java/org/springframework/context/i18n/LocaleContextHolder.java index fd8875b9a2..b6fa354bf8 100644 --- a/spring-context/src/main/java/org/springframework/context/i18n/LocaleContextHolder.java +++ b/spring-context/src/main/java/org/springframework/context/i18n/LocaleContextHolder.java @@ -21,6 +21,7 @@ import java.util.TimeZone; import org.springframework.core.NamedInheritableThreadLocal; import org.springframework.core.NamedThreadLocal; +import org.springframework.lang.Nullable; /** * Simple holder class that associates a LocaleContext instance @@ -74,7 +75,7 @@ public abstract class LocaleContextHolder { * @see SimpleLocaleContext * @see SimpleTimeZoneAwareLocaleContext */ - public static void setLocaleContext(LocaleContext localeContext) { + public static void setLocaleContext(@Nullable LocaleContext localeContext) { setLocaleContext(localeContext, false); } @@ -89,7 +90,7 @@ public abstract class LocaleContextHolder { * @see SimpleLocaleContext * @see SimpleTimeZoneAwareLocaleContext */ - public static void setLocaleContext(LocaleContext localeContext, boolean inheritable) { + public static void setLocaleContext(@Nullable LocaleContext localeContext, boolean inheritable) { if (localeContext == null) { resetLocaleContext(); } @@ -109,6 +110,7 @@ public abstract class LocaleContextHolder { * Return the LocaleContext associated with the current thread, if any. * @return the current LocaleContext, or {@code null} if none */ + @Nullable public static LocaleContext getLocaleContext() { LocaleContext localeContext = localeContextHolder.get(); if (localeContext == null) { @@ -127,7 +129,7 @@ public abstract class LocaleContextHolder { * @see #setTimeZone(TimeZone) * @see SimpleLocaleContext#SimpleLocaleContext(Locale) */ - public static void setLocale(Locale locale) { + public static void setLocale(@Nullable Locale locale) { setLocale(locale, false); } @@ -142,7 +144,7 @@ public abstract class LocaleContextHolder { * @see #setTimeZone(TimeZone, boolean) * @see SimpleLocaleContext#SimpleLocaleContext(Locale) */ - public static void setLocale(Locale locale, boolean inheritable) { + public static void setLocale(@Nullable Locale locale, boolean inheritable) { LocaleContext localeContext = getLocaleContext(); TimeZone timeZone = (localeContext instanceof TimeZoneAwareLocaleContext ? ((TimeZoneAwareLocaleContext) localeContext).getTimeZone() : null); @@ -172,7 +174,7 @@ public abstract class LocaleContextHolder { * @see #getLocale() * @see Locale#getDefault() */ - public static void setDefaultLocale(Locale locale) { + public static void setDefaultLocale(@Nullable Locale locale) { LocaleContextHolder.defaultLocale = locale; } @@ -213,7 +215,7 @@ public abstract class LocaleContextHolder { * @see #setLocale(Locale) * @see SimpleTimeZoneAwareLocaleContext#SimpleTimeZoneAwareLocaleContext(Locale, TimeZone) */ - public static void setTimeZone(TimeZone timeZone) { + public static void setTimeZone(@Nullable TimeZone timeZone) { setTimeZone(timeZone, false); } @@ -228,7 +230,7 @@ public abstract class LocaleContextHolder { * @see #setLocale(Locale, boolean) * @see SimpleTimeZoneAwareLocaleContext#SimpleTimeZoneAwareLocaleContext(Locale, TimeZone) */ - public static void setTimeZone(TimeZone timeZone, boolean inheritable) { + public static void setTimeZone(@Nullable TimeZone timeZone, boolean inheritable) { LocaleContext localeContext = getLocaleContext(); Locale locale = (localeContext != null ? localeContext.getLocale() : null); if (timeZone != null) { @@ -257,7 +259,7 @@ public abstract class LocaleContextHolder { * @see #getTimeZone() * @see TimeZone#getDefault() */ - public static void setDefaultTimeZone(TimeZone timeZone) { + public static void setDefaultTimeZone(@Nullable TimeZone timeZone) { defaultTimeZone = timeZone; } diff --git a/spring-context/src/main/java/org/springframework/context/i18n/TimeZoneAwareLocaleContext.java b/spring-context/src/main/java/org/springframework/context/i18n/TimeZoneAwareLocaleContext.java index 825e0ecd04..186afeb4da 100644 --- a/spring-context/src/main/java/org/springframework/context/i18n/TimeZoneAwareLocaleContext.java +++ b/spring-context/src/main/java/org/springframework/context/i18n/TimeZoneAwareLocaleContext.java @@ -18,6 +18,8 @@ package org.springframework.context.i18n; import java.util.TimeZone; +import org.springframework.lang.Nullable; + /** * Extension of {@link LocaleContext}, adding awareness of the current time zone. * @@ -37,6 +39,7 @@ public interface TimeZoneAwareLocaleContext extends LocaleContext { * depending on the implementation strategy. * @return the current TimeZone, or {@code null} if no specific TimeZone associated */ + @Nullable TimeZone getTimeZone(); } diff --git a/spring-context/src/main/java/org/springframework/context/i18n/package-info.java b/spring-context/src/main/java/org/springframework/context/i18n/package-info.java index 1bad27837c..41c681a297 100644 --- a/spring-context/src/main/java/org/springframework/context/i18n/package-info.java +++ b/spring-context/src/main/java/org/springframework/context/i18n/package-info.java @@ -2,4 +2,7 @@ * Abstraction for determining the current Locale, * plus global holder that exposes a thread-bound Locale. */ +@NonNullApi package org.springframework.context.i18n; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context/src/main/java/org/springframework/context/index/CandidateComponentsIndexLoader.java b/spring-context/src/main/java/org/springframework/context/index/CandidateComponentsIndexLoader.java index bdb649d264..02d85b9a49 100644 --- a/spring-context/src/main/java/org/springframework/context/index/CandidateComponentsIndexLoader.java +++ b/spring-context/src/main/java/org/springframework/context/index/CandidateComponentsIndexLoader.java @@ -30,6 +30,7 @@ import org.apache.commons.logging.LogFactory; import org.springframework.core.SpringProperties; import org.springframework.core.io.UrlResource; import org.springframework.core.io.support.PropertiesLoaderUtils; +import org.springframework.lang.Nullable; import org.springframework.util.ConcurrentReferenceHashMap; /** @@ -75,7 +76,8 @@ public class CandidateComponentsIndexLoader { * @throws IllegalArgumentException if any module index cannot * be loaded or if an error occurs while creating {@link CandidateComponentsIndex} */ - public static CandidateComponentsIndex loadIndex(ClassLoader classLoader) { + @Nullable + public static CandidateComponentsIndex loadIndex(@Nullable ClassLoader classLoader) { ClassLoader classLoaderToUse = classLoader; if (classLoaderToUse == null) { classLoaderToUse = CandidateComponentsIndexLoader.class.getClassLoader(); @@ -83,6 +85,7 @@ public class CandidateComponentsIndexLoader { return cache.computeIfAbsent(classLoaderToUse, CandidateComponentsIndexLoader::doLoadIndex); } + @Nullable private static CandidateComponentsIndex doLoadIndex(ClassLoader classLoader) { if (shouldIgnoreIndex) { return null; diff --git a/spring-context/src/main/java/org/springframework/context/index/package-info.java b/spring-context/src/main/java/org/springframework/context/index/package-info.java index 25c09d5c6d..4793fd57ea 100644 --- a/spring-context/src/main/java/org/springframework/context/index/package-info.java +++ b/spring-context/src/main/java/org/springframework/context/index/package-info.java @@ -1,4 +1,7 @@ /** * Support package for reading and managing the components index. */ +@NonNullApi package org.springframework.context.index; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context/src/main/java/org/springframework/context/package-info.java b/spring-context/src/main/java/org/springframework/context/package-info.java index 357cee5d73..3f08f4ef0b 100644 --- a/spring-context/src/main/java/org/springframework/context/package-info.java +++ b/spring-context/src/main/java/org/springframework/context/package-info.java @@ -10,4 +10,7 @@ * is that application objects can often be configured without * any dependency on Spring-specific APIs. */ +@NonNullApi package org.springframework.context; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context/src/main/java/org/springframework/context/support/AbstractMessageSource.java b/spring-context/src/main/java/org/springframework/context/support/AbstractMessageSource.java index 6dcd90989b..307cd0b23a 100644 --- a/spring-context/src/main/java/org/springframework/context/support/AbstractMessageSource.java +++ b/spring-context/src/main/java/org/springframework/context/support/AbstractMessageSource.java @@ -26,6 +26,7 @@ import org.springframework.context.HierarchicalMessageSource; import org.springframework.context.MessageSource; import org.springframework.context.MessageSourceResolvable; import org.springframework.context.NoSuchMessageException; +import org.springframework.lang.Nullable; import org.springframework.util.ObjectUtils; /** @@ -93,6 +94,7 @@ public abstract class AbstractMessageSource extends MessageSourceSupport impleme /** * Return a Properties object defining locale-independent common messages, if any. */ + @Nullable protected Properties getCommonMessages() { return this.commonMessages; } @@ -192,6 +194,7 @@ public abstract class AbstractMessageSource extends MessageSourceSupport impleme * @see #getMessage(MessageSourceResolvable, Locale) * @see #setUseCodeAsDefaultMessage */ + @Nullable protected String getMessageInternal(String code, Object[] args, Locale locale) { if (code == null) { return null; @@ -248,6 +251,7 @@ public abstract class AbstractMessageSource extends MessageSourceSupport impleme * @return the resolved message, or {@code null} if not found * @see #getParentMessageSource() */ + @Nullable protected String getMessageFromParent(String code, Object[] args, Locale locale) { MessageSource parent = getParentMessageSource(); if (parent != null) { @@ -277,6 +281,7 @@ public abstract class AbstractMessageSource extends MessageSourceSupport impleme * @see #renderDefaultMessage(String, Object[], Locale) * @see #getDefaultMessage(String) */ + @Nullable protected String getDefaultMessage(MessageSourceResolvable resolvable, Locale locale) { String defaultMessage = resolvable.getDefaultMessage(); String[] codes = resolvable.getCodes(); @@ -300,6 +305,7 @@ public abstract class AbstractMessageSource extends MessageSourceSupport impleme * @return the default message to use, or {@code null} if none * @see #setUseCodeAsDefaultMessage */ + @Nullable protected String getDefaultMessage(String code) { if (isUseCodeAsDefaultMessage()) { return code; @@ -350,6 +356,7 @@ public abstract class AbstractMessageSource extends MessageSourceSupport impleme * @see #resolveCode * @see java.text.MessageFormat */ + @Nullable protected String resolveCodeWithoutArguments(String code, Locale locale) { MessageFormat messageFormat = resolveCode(code, locale); if (messageFormat != null) { @@ -373,6 +380,7 @@ public abstract class AbstractMessageSource extends MessageSourceSupport impleme * @return the MessageFormat for the message, or {@code null} if not found * @see #resolveCodeWithoutArguments(String, java.util.Locale) */ + @Nullable protected abstract MessageFormat resolveCode(String code, Locale locale); } diff --git a/spring-context/src/main/java/org/springframework/context/support/AbstractRefreshableConfigApplicationContext.java b/spring-context/src/main/java/org/springframework/context/support/AbstractRefreshableConfigApplicationContext.java index 0775e5782d..9109f94e7e 100644 --- a/spring-context/src/main/java/org/springframework/context/support/AbstractRefreshableConfigApplicationContext.java +++ b/spring-context/src/main/java/org/springframework/context/support/AbstractRefreshableConfigApplicationContext.java @@ -19,6 +19,7 @@ package org.springframework.context.support; import org.springframework.beans.factory.BeanNameAware; import org.springframework.beans.factory.InitializingBean; import org.springframework.context.ApplicationContext; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -94,6 +95,7 @@ public abstract class AbstractRefreshableConfigApplicationContext extends Abstra * @see #getResources * @see #getResourcePatternResolver */ + @Nullable protected String[] getConfigLocations() { return (this.configLocations != null ? this.configLocations : getDefaultConfigLocations()); } @@ -106,6 +108,7 @@ public abstract class AbstractRefreshableConfigApplicationContext extends Abstra * @return an array of default config locations, if any * @see #setConfigLocations */ + @Nullable protected String[] getDefaultConfigLocations() { return null; } diff --git a/spring-context/src/main/java/org/springframework/context/support/AbstractResourceBasedMessageSource.java b/spring-context/src/main/java/org/springframework/context/support/AbstractResourceBasedMessageSource.java index 5c6bae5777..a97f5e5f8a 100644 --- a/spring-context/src/main/java/org/springframework/context/support/AbstractResourceBasedMessageSource.java +++ b/spring-context/src/main/java/org/springframework/context/support/AbstractResourceBasedMessageSource.java @@ -19,6 +19,7 @@ package org.springframework.context.support; import java.util.LinkedHashSet; import java.util.Set; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; @@ -126,6 +127,7 @@ public abstract class AbstractResourceBasedMessageSource extends AbstractMessage * Return the default charset to use for parsing properties files, if any. * @since 4.3 */ + @Nullable protected String getDefaultEncoding() { return this.defaultEncoding; } diff --git a/spring-context/src/main/java/org/springframework/context/support/AbstractXmlApplicationContext.java b/spring-context/src/main/java/org/springframework/context/support/AbstractXmlApplicationContext.java index 1e7681aa0b..57aedda8ed 100644 --- a/spring-context/src/main/java/org/springframework/context/support/AbstractXmlApplicationContext.java +++ b/spring-context/src/main/java/org/springframework/context/support/AbstractXmlApplicationContext.java @@ -24,6 +24,7 @@ import org.springframework.beans.factory.xml.ResourceEntityResolver; import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; import org.springframework.context.ApplicationContext; import org.springframework.core.io.Resource; +import org.springframework.lang.Nullable; /** * Convenient base class for {@link org.springframework.context.ApplicationContext} @@ -136,6 +137,7 @@ public abstract class AbstractXmlApplicationContext extends AbstractRefreshableC * @return an array of Resource objects, or {@code null} if none * @see #getConfigLocations() */ + @Nullable protected Resource[] getConfigResources() { return null; } diff --git a/spring-context/src/main/java/org/springframework/context/support/GenericApplicationContext.java b/spring-context/src/main/java/org/springframework/context/support/GenericApplicationContext.java index f52b4cd41a..a8ef05ed80 100644 --- a/spring-context/src/main/java/org/springframework/context/support/GenericApplicationContext.java +++ b/spring-context/src/main/java/org/springframework/context/support/GenericApplicationContext.java @@ -34,6 +34,7 @@ import org.springframework.context.ApplicationContext; import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceLoader; import org.springframework.core.io.support.ResourcePatternResolver; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -384,7 +385,7 @@ public class GenericApplicationContext extends AbstractApplicationContext implem * @since 5.0 * @see #registerBean(String, Class, Supplier, BeanDefinitionCustomizer...) */ - public final void registerBean(String beanName, Class beanClass, BeanDefinitionCustomizer... customizers) { + public final void registerBean(@Nullable String beanName, Class beanClass, BeanDefinitionCustomizer... customizers) { registerBean(beanName, beanClass, null, customizers); } @@ -418,7 +419,7 @@ public class GenericApplicationContext extends AbstractApplicationContext implem * factory's {@link BeanDefinition}, e.g. setting a lazy-init or primary flag * @since 5.0 */ - public void registerBean(String beanName, Class beanClass, Supplier supplier, + public void registerBean(@Nullable String beanName, @Nullable Class beanClass, Supplier supplier, BeanDefinitionCustomizer... customizers) { Assert.isTrue(beanName != null || beanClass != null, "Either bean name or bean class must be specified"); diff --git a/spring-context/src/main/java/org/springframework/context/support/LiveBeansView.java b/spring-context/src/main/java/org/springframework/context/support/LiveBeansView.java index eb2b3bd5a9..97d437e120 100644 --- a/spring-context/src/main/java/org/springframework/context/support/LiveBeansView.java +++ b/spring-context/src/main/java/org/springframework/context/support/LiveBeansView.java @@ -31,6 +31,7 @@ import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.context.ApplicationContextException; import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -223,6 +224,7 @@ public class LiveBeansView implements LiveBeansViewMBean, ApplicationContextAwar * @param bd the bean definition to build the resource description for * @return the JSON-escaped resource description */ + @Nullable protected String getEscapedResourceDescription(BeanDefinition bd) { String resourceDescription = bd.getResourceDescription(); if (resourceDescription == null) { diff --git a/spring-context/src/main/java/org/springframework/context/support/MessageSourceAccessor.java b/spring-context/src/main/java/org/springframework/context/support/MessageSourceAccessor.java index 03fa94a525..808766d297 100644 --- a/spring-context/src/main/java/org/springframework/context/support/MessageSourceAccessor.java +++ b/spring-context/src/main/java/org/springframework/context/support/MessageSourceAccessor.java @@ -22,6 +22,7 @@ import org.springframework.context.MessageSource; import org.springframework.context.MessageSourceResolvable; import org.springframework.context.NoSuchMessageException; import org.springframework.context.i18n.LocaleContextHolder; +import org.springframework.lang.Nullable; /** * Helper class for easy access to messages from a MessageSource, @@ -101,7 +102,7 @@ public class MessageSourceAccessor { * @param defaultMessage String to return if the lookup fails * @return the message */ - public String getMessage(String code, Object[] args, String defaultMessage) { + public String getMessage(String code, @Nullable Object[] args, String defaultMessage) { return this.messageSource.getMessage(code, args, defaultMessage, getDefaultLocale()); } @@ -113,7 +114,7 @@ public class MessageSourceAccessor { * @param locale Locale in which to do lookup * @return the message */ - public String getMessage(String code, Object[] args, String defaultMessage, Locale locale) { + public String getMessage(String code, @Nullable Object[] args, String defaultMessage, Locale locale) { return this.messageSource.getMessage(code, args, defaultMessage, locale); } @@ -145,7 +146,7 @@ public class MessageSourceAccessor { * @return the message * @throws org.springframework.context.NoSuchMessageException if not found */ - public String getMessage(String code, Object[] args) throws NoSuchMessageException { + public String getMessage(String code, @Nullable Object[] args) throws NoSuchMessageException { return this.messageSource.getMessage(code, args, getDefaultLocale()); } @@ -157,7 +158,7 @@ public class MessageSourceAccessor { * @return the message * @throws org.springframework.context.NoSuchMessageException if not found */ - public String getMessage(String code, Object[] args, Locale locale) throws NoSuchMessageException { + public String getMessage(String code, @Nullable Object[] args, Locale locale) throws NoSuchMessageException { return this.messageSource.getMessage(code, args, locale); } diff --git a/spring-context/src/main/java/org/springframework/context/support/MessageSourceResourceBundle.java b/spring-context/src/main/java/org/springframework/context/support/MessageSourceResourceBundle.java index 605aa72e87..31ff104378 100644 --- a/spring-context/src/main/java/org/springframework/context/support/MessageSourceResourceBundle.java +++ b/spring-context/src/main/java/org/springframework/context/support/MessageSourceResourceBundle.java @@ -22,6 +22,7 @@ import java.util.ResourceBundle; import org.springframework.context.MessageSource; import org.springframework.context.NoSuchMessageException; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -70,6 +71,7 @@ public class MessageSourceResourceBundle extends ResourceBundle { * Returns {@code null} if the message could not be resolved. */ @Override + @Nullable protected Object handleGetObject(String key) { try { return this.messageSource.getMessage(key, null, this.locale); diff --git a/spring-context/src/main/java/org/springframework/context/support/MessageSourceSupport.java b/spring-context/src/main/java/org/springframework/context/support/MessageSourceSupport.java index d7e175d8a8..86d877ce9c 100644 --- a/spring-context/src/main/java/org/springframework/context/support/MessageSourceSupport.java +++ b/spring-context/src/main/java/org/springframework/context/support/MessageSourceSupport.java @@ -24,6 +24,7 @@ import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.lang.Nullable; import org.springframework.util.ObjectUtils; /** @@ -96,7 +97,7 @@ public abstract class MessageSourceSupport { * @return the rendered default message (with resolved arguments) * @see #formatMessage(String, Object[], java.util.Locale) */ - protected String renderDefaultMessage(String defaultMessage, Object[] args, Locale locale) { + protected String renderDefaultMessage(String defaultMessage, @Nullable Object[] args, Locale locale) { return formatMessage(defaultMessage, args, locale); } diff --git a/spring-context/src/main/java/org/springframework/context/support/ReloadableResourceBundleMessageSource.java b/spring-context/src/main/java/org/springframework/context/support/ReloadableResourceBundleMessageSource.java index b281902eb2..b144f245d3 100644 --- a/spring-context/src/main/java/org/springframework/context/support/ReloadableResourceBundleMessageSource.java +++ b/spring-context/src/main/java/org/springframework/context/support/ReloadableResourceBundleMessageSource.java @@ -33,6 +33,7 @@ import org.springframework.context.ResourceLoaderAware; import org.springframework.core.io.DefaultResourceLoader; import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceLoader; +import org.springframework.lang.Nullable; import org.springframework.util.DefaultPropertiesPersister; import org.springframework.util.PropertiesPersister; import org.springframework.util.StringUtils; @@ -395,7 +396,7 @@ public class ReloadableResourceBundleMessageSource extends AbstractResourceBased * @param filename the bundle filename (basename + Locale) * @param propHolder the current PropertiesHolder for the bundle */ - protected PropertiesHolder refreshProperties(String filename, PropertiesHolder propHolder) { + protected PropertiesHolder refreshProperties(String filename, @Nullable PropertiesHolder propHolder) { long refreshTimestamp = (getCacheMillis() < 0 ? -1 : System.currentTimeMillis()); Resource resource = this.resourceLoader.getResource(filename + PROPERTIES_SUFFIX); @@ -585,6 +586,7 @@ public class ReloadableResourceBundleMessageSource extends AbstractResourceBased return this.refreshTimestamp; } + @Nullable public String getProperty(String code) { if (this.properties == null) { return null; @@ -592,6 +594,7 @@ public class ReloadableResourceBundleMessageSource extends AbstractResourceBased return this.properties.getProperty(code); } + @Nullable public MessageFormat getMessageFormat(String code, Locale locale) { if (this.properties == null) { return null; diff --git a/spring-context/src/main/java/org/springframework/context/support/ResourceBundleMessageSource.java b/spring-context/src/main/java/org/springframework/context/support/ResourceBundleMessageSource.java index 3417ae508b..d70b21b633 100644 --- a/spring-context/src/main/java/org/springframework/context/support/ResourceBundleMessageSource.java +++ b/spring-context/src/main/java/org/springframework/context/support/ResourceBundleMessageSource.java @@ -35,6 +35,7 @@ import java.util.ResourceBundle; import java.util.Set; import org.springframework.beans.factory.BeanClassLoaderAware; +import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; /** @@ -165,6 +166,7 @@ public class ResourceBundleMessageSource extends AbstractResourceBasedMessageSou * @return the resulting ResourceBundle, or {@code null} if none * found for the given basename and Locale */ + @Nullable protected ResourceBundle getResourceBundle(String basename, Locale locale) { if (getCacheMillis() >= 0) { // Fresh ResourceBundle.getBundle call in order to let ResourceBundle @@ -238,6 +240,7 @@ public class ResourceBundleMessageSource extends AbstractResourceBasedMessageSou * defined for the given code * @throws MissingResourceException if thrown by the ResourceBundle */ + @Nullable protected MessageFormat getMessageFormat(ResourceBundle bundle, String code, Locale locale) throws MissingResourceException { @@ -287,6 +290,7 @@ public class ResourceBundleMessageSource extends AbstractResourceBasedMessageSou * @see ResourceBundle#getString(String) * @see ResourceBundle#containsKey(String) */ + @Nullable protected String getStringOrNull(ResourceBundle bundle, String key) { if (bundle.containsKey(key)) { try { diff --git a/spring-context/src/main/java/org/springframework/context/support/package-info.java b/spring-context/src/main/java/org/springframework/context/support/package-info.java index da9f3cafdd..c84723e8e0 100644 --- a/spring-context/src/main/java/org/springframework/context/support/package-info.java +++ b/spring-context/src/main/java/org/springframework/context/support/package-info.java @@ -3,4 +3,7 @@ * such as abstract base classes for ApplicationContext * implementations and a MessageSource implementation. */ +@NonNullApi package org.springframework.context.support; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context/src/main/java/org/springframework/context/weaving/AspectJWeavingEnabler.java b/spring-context/src/main/java/org/springframework/context/weaving/AspectJWeavingEnabler.java index e93e500baf..ec5627bf07 100644 --- a/spring-context/src/main/java/org/springframework/context/weaving/AspectJWeavingEnabler.java +++ b/spring-context/src/main/java/org/springframework/context/weaving/AspectJWeavingEnabler.java @@ -29,6 +29,7 @@ import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.core.Ordered; import org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver; import org.springframework.instrument.classloading.LoadTimeWeaver; +import org.springframework.lang.Nullable; /** * Post-processor that registers AspectJ's @@ -77,7 +78,7 @@ public class AspectJWeavingEnabler * @param weaverToUse the LoadTimeWeaver to apply to (or {@code null} for a default weaver) * @param beanClassLoader the class loader to create a default weaver for (if necessary) */ - public static void enableAspectJWeaving(LoadTimeWeaver weaverToUse, ClassLoader beanClassLoader) { + public static void enableAspectJWeaving(@Nullable LoadTimeWeaver weaverToUse, ClassLoader beanClassLoader) { if (weaverToUse == null) { if (InstrumentationLoadTimeWeaver.isInstrumentationAvailable()) { weaverToUse = new InstrumentationLoadTimeWeaver(beanClassLoader); diff --git a/spring-context/src/main/java/org/springframework/context/weaving/DefaultContextLoadTimeWeaver.java b/spring-context/src/main/java/org/springframework/context/weaving/DefaultContextLoadTimeWeaver.java index 65d5a6c204..1299a21652 100644 --- a/spring-context/src/main/java/org/springframework/context/weaving/DefaultContextLoadTimeWeaver.java +++ b/spring-context/src/main/java/org/springframework/context/weaving/DefaultContextLoadTimeWeaver.java @@ -32,6 +32,7 @@ import org.springframework.instrument.classloading.jboss.JBossLoadTimeWeaver; import org.springframework.instrument.classloading.tomcat.TomcatLoadTimeWeaver; import org.springframework.instrument.classloading.weblogic.WebLogicLoadTimeWeaver; import org.springframework.instrument.classloading.websphere.WebSphereLoadTimeWeaver; +import org.springframework.lang.Nullable; /** * Default {@link LoadTimeWeaver} bean for use in an application context, @@ -105,6 +106,7 @@ public class DefaultContextLoadTimeWeaver implements LoadTimeWeaver, BeanClassLo * of a specific method (addInstanceClassPreProcessor) for any earlier * versions even though the ClassLoader name is the same. */ + @Nullable protected LoadTimeWeaver createServerSpecificLoadTimeWeaver(ClassLoader classLoader) { String name = classLoader.getClass().getName(); try { diff --git a/spring-context/src/main/java/org/springframework/context/weaving/LoadTimeWeaverAwareProcessor.java b/spring-context/src/main/java/org/springframework/context/weaving/LoadTimeWeaverAwareProcessor.java index 7509b8beff..22ceb478ec 100644 --- a/spring-context/src/main/java/org/springframework/context/weaving/LoadTimeWeaverAwareProcessor.java +++ b/spring-context/src/main/java/org/springframework/context/weaving/LoadTimeWeaverAwareProcessor.java @@ -22,6 +22,7 @@ import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.instrument.classloading.LoadTimeWeaver; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -65,7 +66,7 @@ public class LoadTimeWeaverAwareProcessor implements BeanPostProcessor, BeanFact * {@link ConfigurableApplicationContext#LOAD_TIME_WEAVER_BEAN_NAME "loadTimeWeaver"}. * @param loadTimeWeaver the specific {@code LoadTimeWeaver} that is to be used */ - public LoadTimeWeaverAwareProcessor(LoadTimeWeaver loadTimeWeaver) { + public LoadTimeWeaverAwareProcessor(@Nullable LoadTimeWeaver loadTimeWeaver) { this.loadTimeWeaver = loadTimeWeaver; } diff --git a/spring-context/src/main/java/org/springframework/context/weaving/package-info.java b/spring-context/src/main/java/org/springframework/context/weaving/package-info.java index 68b06e332b..533a21bedb 100644 --- a/spring-context/src/main/java/org/springframework/context/weaving/package-info.java +++ b/spring-context/src/main/java/org/springframework/context/weaving/package-info.java @@ -2,4 +2,7 @@ * Load-time weaving support for a Spring application context, building on Spring's * {@link org.springframework.instrument.classloading.LoadTimeWeaver} abstraction. */ +@NonNullApi package org.springframework.context.weaving; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context/src/main/java/org/springframework/ejb/access/AbstractRemoteSlsbInvokerInterceptor.java b/spring-context/src/main/java/org/springframework/ejb/access/AbstractRemoteSlsbInvokerInterceptor.java index 2bb1b146ae..d785341b26 100644 --- a/spring-context/src/main/java/org/springframework/ejb/access/AbstractRemoteSlsbInvokerInterceptor.java +++ b/spring-context/src/main/java/org/springframework/ejb/access/AbstractRemoteSlsbInvokerInterceptor.java @@ -25,6 +25,7 @@ import javax.naming.NamingException; import org.aopalliance.intercept.MethodInvocation; +import org.springframework.lang.Nullable; import org.springframework.remoting.RemoteConnectFailureException; import org.springframework.remoting.RemoteLookupFailureException; import org.springframework.remoting.rmi.RmiClientInterceptorUtils; @@ -164,6 +165,7 @@ public abstract class AbstractRemoteSlsbInvokerInterceptor extends AbstractSlsbI * @throws Throwable in case of invocation failure * @see #invoke */ + @Nullable protected Object refreshAndRetry(MethodInvocation invocation) throws Throwable { try { refreshHome(); @@ -184,6 +186,7 @@ public abstract class AbstractRemoteSlsbInvokerInterceptor extends AbstractSlsbI * @see #getHome * @see #newSessionBeanInstance */ + @Nullable protected abstract Object doInvoke(MethodInvocation invocation) throws Throwable; diff --git a/spring-context/src/main/java/org/springframework/ejb/access/AbstractSlsbInvokerInterceptor.java b/spring-context/src/main/java/org/springframework/ejb/access/AbstractSlsbInvokerInterceptor.java index a9a770f510..7f6ec9a15b 100644 --- a/spring-context/src/main/java/org/springframework/ejb/access/AbstractSlsbInvokerInterceptor.java +++ b/spring-context/src/main/java/org/springframework/ejb/access/AbstractSlsbInvokerInterceptor.java @@ -25,6 +25,7 @@ import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; import org.springframework.jndi.JndiObjectLocator; +import org.springframework.lang.Nullable; /** * Base class for AOP interceptors invoking local or remote Stateless Session Beans. @@ -132,6 +133,7 @@ public abstract class AbstractSlsbInvokerInterceptor extends JndiObjectLocator * @return the create method * @throws EjbAccessException if the method couldn't be retrieved */ + @Nullable protected Method getCreateMethod(Object home) throws EjbAccessException { try { // Cache the EJB create() method that must be declared on the home interface. @@ -201,6 +203,7 @@ public abstract class AbstractSlsbInvokerInterceptor extends JndiObjectLocator * @return the invocation result, if any * @throws Throwable in case of invocation failure */ + @Nullable protected abstract Object invokeInContext(MethodInvocation invocation) throws Throwable; diff --git a/spring-context/src/main/java/org/springframework/ejb/access/package-info.java b/spring-context/src/main/java/org/springframework/ejb/access/package-info.java index 523280e2e4..bc4fcfdf62 100644 --- a/spring-context/src/main/java/org/springframework/ejb/access/package-info.java +++ b/spring-context/src/main/java/org/springframework/ejb/access/package-info.java @@ -19,4 +19,7 @@ * It now uses FactoryBeans and AOP, rather than the custom bean definitions described in * Expert One-on-One J2EE. */ +@NonNullApi package org.springframework.ejb.access; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context/src/main/java/org/springframework/ejb/config/package-info.java b/spring-context/src/main/java/org/springframework/ejb/config/package-info.java index ccb26f87bb..7cdd105347 100644 --- a/spring-context/src/main/java/org/springframework/ejb/config/package-info.java +++ b/spring-context/src/main/java/org/springframework/ejb/config/package-info.java @@ -2,4 +2,7 @@ * Support package for EJB/Java EE-related configuration, * with XML schema being the primary configuration format. */ +@NonNullApi package org.springframework.ejb.config; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context/src/main/java/org/springframework/format/annotation/package-info.java b/spring-context/src/main/java/org/springframework/format/annotation/package-info.java index 3656baa169..88d246417c 100644 --- a/spring-context/src/main/java/org/springframework/format/annotation/package-info.java +++ b/spring-context/src/main/java/org/springframework/format/annotation/package-info.java @@ -1,4 +1,7 @@ /** * Annotations for declaratively configuring field formatting rules. */ +@NonNullApi package org.springframework.format.annotation; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context/src/main/java/org/springframework/format/datetime/joda/DateTimeFormatterFactory.java b/spring-context/src/main/java/org/springframework/format/datetime/joda/DateTimeFormatterFactory.java index d0efdaa3a1..1bacf2b4dd 100644 --- a/spring-context/src/main/java/org/springframework/format/datetime/joda/DateTimeFormatterFactory.java +++ b/spring-context/src/main/java/org/springframework/format/datetime/joda/DateTimeFormatterFactory.java @@ -24,6 +24,7 @@ import org.joda.time.format.DateTimeFormatter; import org.joda.time.format.ISODateTimeFormat; import org.springframework.format.annotation.DateTimeFormat.ISO; +import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; /** @@ -129,7 +130,7 @@ public class DateTimeFormatterFactory { * factory properties have been set (can be {@code null}). * @return a new date time formatter */ - public DateTimeFormatter createDateTimeFormatter(DateTimeFormatter fallbackFormatter) { + public DateTimeFormatter createDateTimeFormatter(@Nullable DateTimeFormatter fallbackFormatter) { DateTimeFormatter dateTimeFormatter = null; if (StringUtils.hasLength(this.pattern)) { dateTimeFormatter = DateTimeFormat.forPattern(this.pattern); diff --git a/spring-context/src/main/java/org/springframework/format/datetime/joda/JodaTimeContext.java b/spring-context/src/main/java/org/springframework/format/datetime/joda/JodaTimeContext.java index b5c2766c7a..4c8c2a0090 100644 --- a/spring-context/src/main/java/org/springframework/format/datetime/joda/JodaTimeContext.java +++ b/spring-context/src/main/java/org/springframework/format/datetime/joda/JodaTimeContext.java @@ -25,6 +25,7 @@ import org.joda.time.format.DateTimeFormatter; import org.springframework.context.i18n.LocaleContext; import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.context.i18n.TimeZoneAwareLocaleContext; +import org.springframework.lang.Nullable; /** * A context that holds user-specific Joda-Time settings such as the user's @@ -53,6 +54,7 @@ public class JodaTimeContext { /** * Return the user's chronology (calendar system), if any. */ + @Nullable public Chronology getChronology() { return this.chronology; } @@ -72,6 +74,7 @@ public class JodaTimeContext { /** * Return the user's time zone, if any. */ + @Nullable public DateTimeZone getTimeZone() { return this.timeZone; } diff --git a/spring-context/src/main/java/org/springframework/format/datetime/joda/JodaTimeContextHolder.java b/spring-context/src/main/java/org/springframework/format/datetime/joda/JodaTimeContextHolder.java index 631420b256..7b6148d9ba 100644 --- a/spring-context/src/main/java/org/springframework/format/datetime/joda/JodaTimeContextHolder.java +++ b/spring-context/src/main/java/org/springframework/format/datetime/joda/JodaTimeContextHolder.java @@ -21,6 +21,7 @@ import java.util.Locale; import org.joda.time.format.DateTimeFormatter; import org.springframework.core.NamedThreadLocal; +import org.springframework.lang.Nullable; /** * A holder for a thread-local {@link JodaTimeContext} @@ -49,7 +50,7 @@ public final class JodaTimeContextHolder { * @param jodaTimeContext the current JodaTimeContext, * or {@code null} to reset the thread-bound context */ - public static void setJodaTimeContext(JodaTimeContext jodaTimeContext) { + public static void setJodaTimeContext(@Nullable JodaTimeContext jodaTimeContext) { if (jodaTimeContext == null) { resetJodaTimeContext(); } @@ -62,6 +63,7 @@ public final class JodaTimeContextHolder { * Return the JodaTimeContext associated with the current thread, if any. * @return the current JodaTimeContext, or {@code null} if none */ + @Nullable public static JodaTimeContext getJodaTimeContext() { return jodaTimeContextHolder.get(); } @@ -74,7 +76,7 @@ public final class JodaTimeContextHolder { * @param locale the current user locale (may be {@code null} if not known) * @return the user-specific DateTimeFormatter */ - public static DateTimeFormatter getFormatter(DateTimeFormatter formatter, Locale locale) { + public static DateTimeFormatter getFormatter(DateTimeFormatter formatter, @Nullable Locale locale) { DateTimeFormatter formatterToUse = (locale != null ? formatter.withLocale(locale) : formatter); JodaTimeContext context = getJodaTimeContext(); return (context != null ? context.getFormatter(formatterToUse) : formatterToUse); diff --git a/spring-context/src/main/java/org/springframework/format/datetime/joda/package-info.java b/spring-context/src/main/java/org/springframework/format/datetime/joda/package-info.java index 857da5300a..ec5ed44219 100644 --- a/spring-context/src/main/java/org/springframework/format/datetime/joda/package-info.java +++ b/spring-context/src/main/java/org/springframework/format/datetime/joda/package-info.java @@ -1,4 +1,7 @@ /** * Integration with Joda-Time for formatting Joda date and time types as well as standard JDK Date types. */ +@NonNullApi package org.springframework.format.datetime.joda; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context/src/main/java/org/springframework/format/datetime/package-info.java b/spring-context/src/main/java/org/springframework/format/datetime/package-info.java index 62d9dbb0ee..e52e15806f 100644 --- a/spring-context/src/main/java/org/springframework/format/datetime/package-info.java +++ b/spring-context/src/main/java/org/springframework/format/datetime/package-info.java @@ -1,4 +1,7 @@ /** * Formatters for {@code java.util.Date} properties. */ +@NonNullApi package org.springframework.format.datetime; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context/src/main/java/org/springframework/format/datetime/standard/DateTimeContext.java b/spring-context/src/main/java/org/springframework/format/datetime/standard/DateTimeContext.java index 4ef23be208..677348f4f9 100644 --- a/spring-context/src/main/java/org/springframework/format/datetime/standard/DateTimeContext.java +++ b/spring-context/src/main/java/org/springframework/format/datetime/standard/DateTimeContext.java @@ -24,6 +24,7 @@ import java.util.TimeZone; import org.springframework.context.i18n.LocaleContext; import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.context.i18n.TimeZoneAwareLocaleContext; +import org.springframework.lang.Nullable; /** * A context that holds user-specific java.time (JSR-310) settings @@ -51,6 +52,7 @@ public class DateTimeContext { /** * Return the user's chronology (calendar system), if any. */ + @Nullable public Chronology getChronology() { return this.chronology; } @@ -70,6 +72,7 @@ public class DateTimeContext { /** * Return the user's time zone, if any. */ + @Nullable public ZoneId getTimeZone() { return this.timeZone; } diff --git a/spring-context/src/main/java/org/springframework/format/datetime/standard/DateTimeContextHolder.java b/spring-context/src/main/java/org/springframework/format/datetime/standard/DateTimeContextHolder.java index 8a7c072040..44546c7a69 100644 --- a/spring-context/src/main/java/org/springframework/format/datetime/standard/DateTimeContextHolder.java +++ b/spring-context/src/main/java/org/springframework/format/datetime/standard/DateTimeContextHolder.java @@ -20,6 +20,7 @@ import java.time.format.DateTimeFormatter; import java.util.Locale; import org.springframework.core.NamedThreadLocal; +import org.springframework.lang.Nullable; /** * A holder for a thread-local user {@link DateTimeContext}. @@ -46,7 +47,7 @@ public final class DateTimeContextHolder { * @param dateTimeContext the current DateTimeContext, * or {@code null} to reset the thread-bound context */ - public static void setDateTimeContext(DateTimeContext dateTimeContext) { + public static void setDateTimeContext(@Nullable DateTimeContext dateTimeContext) { if (dateTimeContext == null) { resetDateTimeContext(); } @@ -59,6 +60,7 @@ public final class DateTimeContextHolder { * Return the DateTimeContext associated with the current thread, if any. * @return the current DateTimeContext, or {@code null} if none */ + @Nullable public static DateTimeContext getDateTimeContext() { return dateTimeContextHolder.get(); } @@ -71,7 +73,7 @@ public final class DateTimeContextHolder { * @param locale the current user locale (may be {@code null} if not known) * @return the user-specific DateTimeFormatter */ - public static DateTimeFormatter getFormatter(DateTimeFormatter formatter, Locale locale) { + public static DateTimeFormatter getFormatter(DateTimeFormatter formatter, @Nullable Locale locale) { DateTimeFormatter formatterToUse = (locale != null ? formatter.withLocale(locale) : formatter); DateTimeContext context = getDateTimeContext(); return (context != null ? context.getFormatter(formatterToUse) : formatterToUse); diff --git a/spring-context/src/main/java/org/springframework/format/datetime/standard/DateTimeFormatterFactory.java b/spring-context/src/main/java/org/springframework/format/datetime/standard/DateTimeFormatterFactory.java index 18f10bdfad..c2126d3c1d 100644 --- a/spring-context/src/main/java/org/springframework/format/datetime/standard/DateTimeFormatterFactory.java +++ b/spring-context/src/main/java/org/springframework/format/datetime/standard/DateTimeFormatterFactory.java @@ -22,6 +22,7 @@ import java.time.format.ResolverStyle; import java.util.TimeZone; import org.springframework.format.annotation.DateTimeFormat.ISO; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -131,6 +132,7 @@ public class DateTimeFormatterFactory { this.timeStyle = convertStyleCharacter(style.charAt(1)); } + @Nullable private FormatStyle convertStyleCharacter(char c) { switch (c) { case 'S': return FormatStyle.SHORT; @@ -170,7 +172,7 @@ public class DateTimeFormatterFactory { * factory properties have been set (can be {@code null}). * @return a new date time formatter */ - public DateTimeFormatter createDateTimeFormatter(DateTimeFormatter fallbackFormatter) { + public DateTimeFormatter createDateTimeFormatter(@Nullable DateTimeFormatter fallbackFormatter) { DateTimeFormatter dateTimeFormatter = null; if (StringUtils.hasLength(this.pattern)) { // Using strict parsing to align with Joda-Time and standard DateFormat behavior: diff --git a/spring-context/src/main/java/org/springframework/format/datetime/standard/package-info.java b/spring-context/src/main/java/org/springframework/format/datetime/standard/package-info.java index 31c142dcd6..90341d52ec 100644 --- a/spring-context/src/main/java/org/springframework/format/datetime/standard/package-info.java +++ b/spring-context/src/main/java/org/springframework/format/datetime/standard/package-info.java @@ -1,4 +1,7 @@ /** * Integration with the JSR-310 java.time package in JDK 8. */ +@NonNullApi package org.springframework.format.datetime.standard; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context/src/main/java/org/springframework/format/number/money/package-info.java b/spring-context/src/main/java/org/springframework/format/number/money/package-info.java index d19fccfc37..1e9169ff46 100644 --- a/spring-context/src/main/java/org/springframework/format/number/money/package-info.java +++ b/spring-context/src/main/java/org/springframework/format/number/money/package-info.java @@ -1,4 +1,7 @@ /** * Integration with the JSR-354 javax.money package. */ +@NonNullApi package org.springframework.format.number.money; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context/src/main/java/org/springframework/format/number/package-info.java b/spring-context/src/main/java/org/springframework/format/number/package-info.java index f406a63fd0..538351d7a2 100644 --- a/spring-context/src/main/java/org/springframework/format/number/package-info.java +++ b/spring-context/src/main/java/org/springframework/format/number/package-info.java @@ -1,4 +1,7 @@ /** * Formatters for {@code java.lang.Number} properties. */ +@NonNullApi package org.springframework.format.number; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context/src/main/java/org/springframework/format/package-info.java b/spring-context/src/main/java/org/springframework/format/package-info.java index 0f98f75c59..4c03ccf2f7 100644 --- a/spring-context/src/main/java/org/springframework/format/package-info.java +++ b/spring-context/src/main/java/org/springframework/format/package-info.java @@ -1,4 +1,7 @@ /** * An API for defining Formatters to format field model values for display in a UI. */ +@NonNullApi package org.springframework.format; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context/src/main/java/org/springframework/format/support/package-info.java b/spring-context/src/main/java/org/springframework/format/support/package-info.java index f653d54081..8b44df0e34 100644 --- a/spring-context/src/main/java/org/springframework/format/support/package-info.java +++ b/spring-context/src/main/java/org/springframework/format/support/package-info.java @@ -2,4 +2,7 @@ * Support classes for the formatting package, * providing common implementations as well as adapters. */ +@NonNullApi package org.springframework.format.support; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context/src/main/java/org/springframework/instrument/classloading/InstrumentationLoadTimeWeaver.java b/spring-context/src/main/java/org/springframework/instrument/classloading/InstrumentationLoadTimeWeaver.java index 827b56e9f2..2a8ec58a11 100644 --- a/spring-context/src/main/java/org/springframework/instrument/classloading/InstrumentationLoadTimeWeaver.java +++ b/spring-context/src/main/java/org/springframework/instrument/classloading/InstrumentationLoadTimeWeaver.java @@ -24,6 +24,7 @@ import java.util.ArrayList; import java.util.List; import org.springframework.instrument.InstrumentationSavingAgent; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; @@ -139,6 +140,7 @@ public class InstrumentationLoadTimeWeaver implements LoadTimeWeaver { * @return the Instrumentation instance, or {@code null} if none found * @see #isInstrumentationAvailable() */ + @Nullable private static Instrumentation getInstrumentation() { if (AGENT_CLASS_PRESENT) { return InstrumentationAccessor.getInstrumentation(); @@ -175,6 +177,7 @@ public class InstrumentationLoadTimeWeaver implements LoadTimeWeaver { } @Override + @Nullable public byte[] transform(ClassLoader loader, String className, Class classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException { diff --git a/spring-context/src/main/java/org/springframework/instrument/classloading/glassfish/package-info.java b/spring-context/src/main/java/org/springframework/instrument/classloading/glassfish/package-info.java index b282705390..04734b910e 100644 --- a/spring-context/src/main/java/org/springframework/instrument/classloading/glassfish/package-info.java +++ b/spring-context/src/main/java/org/springframework/instrument/classloading/glassfish/package-info.java @@ -1,4 +1,7 @@ /** * Support for class instrumentation on GlassFish. */ +@NonNullApi package org.springframework.instrument.classloading.glassfish; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context/src/main/java/org/springframework/instrument/classloading/jboss/package-info.java b/spring-context/src/main/java/org/springframework/instrument/classloading/jboss/package-info.java index e746ce5e7f..50447e4593 100644 --- a/spring-context/src/main/java/org/springframework/instrument/classloading/jboss/package-info.java +++ b/spring-context/src/main/java/org/springframework/instrument/classloading/jboss/package-info.java @@ -1,4 +1,7 @@ /** * Support for class instrumentation on JBoss AS 6 and 7. */ +@NonNullApi package org.springframework.instrument.classloading.jboss; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context/src/main/java/org/springframework/instrument/classloading/package-info.java b/spring-context/src/main/java/org/springframework/instrument/classloading/package-info.java index c1b7cf3d2c..8714f2dba6 100644 --- a/spring-context/src/main/java/org/springframework/instrument/classloading/package-info.java +++ b/spring-context/src/main/java/org/springframework/instrument/classloading/package-info.java @@ -2,4 +2,7 @@ * Support package for load time weaving based on class loaders, * as required by JPA providers (but not JPA-specific). */ +@NonNullApi package org.springframework.instrument.classloading; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context/src/main/java/org/springframework/instrument/classloading/tomcat/package-info.java b/spring-context/src/main/java/org/springframework/instrument/classloading/tomcat/package-info.java index 11c70a1c6c..e5441f1aff 100644 --- a/spring-context/src/main/java/org/springframework/instrument/classloading/tomcat/package-info.java +++ b/spring-context/src/main/java/org/springframework/instrument/classloading/tomcat/package-info.java @@ -1,4 +1,7 @@ /** * Support for class instrumentation on Tomcat. */ +@NonNullApi package org.springframework.instrument.classloading.tomcat; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context/src/main/java/org/springframework/instrument/classloading/weblogic/package-info.java b/spring-context/src/main/java/org/springframework/instrument/classloading/weblogic/package-info.java index c767e969a3..3293ec2ba7 100644 --- a/spring-context/src/main/java/org/springframework/instrument/classloading/weblogic/package-info.java +++ b/spring-context/src/main/java/org/springframework/instrument/classloading/weblogic/package-info.java @@ -1,4 +1,7 @@ /** * Support for class instrumentation on BEA WebLogic 10+. */ +@NonNullApi package org.springframework.instrument.classloading.weblogic; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context/src/main/java/org/springframework/instrument/classloading/websphere/package-info.java b/spring-context/src/main/java/org/springframework/instrument/classloading/websphere/package-info.java index 11c66d85b9..ed9abd0039 100644 --- a/spring-context/src/main/java/org/springframework/instrument/classloading/websphere/package-info.java +++ b/spring-context/src/main/java/org/springframework/instrument/classloading/websphere/package-info.java @@ -1,4 +1,7 @@ /** * Support for class instrumentation on IBM WebSphere Application Server 7+. */ +@NonNullApi package org.springframework.instrument.classloading.websphere; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context/src/main/java/org/springframework/jmx/access/ConnectorDelegate.java b/spring-context/src/main/java/org/springframework/jmx/access/ConnectorDelegate.java index 8490d68020..8b408254dc 100644 --- a/spring-context/src/main/java/org/springframework/jmx/access/ConnectorDelegate.java +++ b/spring-context/src/main/java/org/springframework/jmx/access/ConnectorDelegate.java @@ -28,6 +28,7 @@ import org.apache.commons.logging.LogFactory; import org.springframework.jmx.MBeanServerNotFoundException; import org.springframework.jmx.support.JmxUtils; +import org.springframework.lang.Nullable; /** * Internal helper class for managing a JMX connector. @@ -49,7 +50,7 @@ class ConnectorDelegate { * @param environment the JMX environment for the connector (may be {@code null}) * @param agentId the local JMX MBeanServer's agent id (may be {@code null}) */ - public MBeanServerConnection connect(JMXServiceURL serviceUrl, Map environment, String agentId) + public MBeanServerConnection connect(@Nullable JMXServiceURL serviceUrl, @Nullable Map environment, @Nullable String agentId) throws MBeanServerNotFoundException { if (serviceUrl != null) { diff --git a/spring-context/src/main/java/org/springframework/jmx/access/MBeanClientInterceptor.java b/spring-context/src/main/java/org/springframework/jmx/access/MBeanClientInterceptor.java index 6efbb2209e..329c3dc5a3 100644 --- a/spring-context/src/main/java/org/springframework/jmx/access/MBeanClientInterceptor.java +++ b/spring-context/src/main/java/org/springframework/jmx/access/MBeanClientInterceptor.java @@ -61,6 +61,7 @@ import org.springframework.core.MethodParameter; import org.springframework.core.ResolvableType; import org.springframework.jmx.support.JmxUtils; import org.springframework.jmx.support.ObjectNameManager; +import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.util.ReflectionUtils; import org.springframework.util.StringUtils; @@ -224,6 +225,7 @@ public class MBeanClientInterceptor * Return the management interface of the target MBean, * or {@code null} if none specified. */ + @Nullable protected final Class getManagementInterface() { return this.managementInterface; } @@ -460,6 +462,7 @@ public class MBeanClientInterceptor } } + @Nullable private Object invokeAttribute(PropertyDescriptor pd, MethodInvocation invocation) throws JMException, IOException { @@ -527,7 +530,8 @@ public class MBeanClientInterceptor * @return the converted result object, or the passed-in object if no conversion * is necessary */ - protected Object convertResultValueIfNecessary(Object result, MethodParameter parameter) { + @Nullable + protected Object convertResultValueIfNecessary(@Nullable Object result, MethodParameter parameter) { Class targetClass = parameter.getParameterType(); try { if (result == null) { diff --git a/spring-context/src/main/java/org/springframework/jmx/access/package-info.java b/spring-context/src/main/java/org/springframework/jmx/access/package-info.java index 410e754b1a..a97129abba 100644 --- a/spring-context/src/main/java/org/springframework/jmx/access/package-info.java +++ b/spring-context/src/main/java/org/springframework/jmx/access/package-info.java @@ -1,4 +1,7 @@ /** * Provides support for accessing remote MBean resources. */ +@NonNullApi package org.springframework.jmx.access; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context/src/main/java/org/springframework/jmx/export/MBeanExporter.java b/spring-context/src/main/java/org/springframework/jmx/export/MBeanExporter.java index 4385854cb9..32e09d9d35 100644 --- a/spring-context/src/main/java/org/springframework/jmx/export/MBeanExporter.java +++ b/spring-context/src/main/java/org/springframework/jmx/export/MBeanExporter.java @@ -63,6 +63,7 @@ import org.springframework.jmx.export.notification.ModelMBeanNotificationPublish import org.springframework.jmx.export.notification.NotificationPublisherAware; import org.springframework.jmx.support.JmxUtils; import org.springframework.jmx.support.MBeanRegistrationSupport; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.CollectionUtils; @@ -585,6 +586,7 @@ public class MBeanExporter extends MBeanRegistrationSupport implements MBeanExpo * @see #registerBeanInstance * @see #registerLazyInit */ + @Nullable protected ObjectName registerBeanNameOrInstance(Object mapValue, String beanKey) throws MBeanExportException { try { if (mapValue instanceof String) { @@ -779,6 +781,7 @@ public class MBeanExporter extends MBeanRegistrationSupport implements MBeanExpo * @return the adapted MBean, or {@code null} if not possible */ @SuppressWarnings("unchecked") + @Nullable protected DynamicMBean adaptMBeanIfPossible(Object bean) throws JMException { Class targetClass = AopUtils.getTargetClass(bean); if (targetClass != bean.getClass()) { diff --git a/spring-context/src/main/java/org/springframework/jmx/export/annotation/package-info.java b/spring-context/src/main/java/org/springframework/jmx/export/annotation/package-info.java index 80ac35387d..6a9da5ccc9 100644 --- a/spring-context/src/main/java/org/springframework/jmx/export/annotation/package-info.java +++ b/spring-context/src/main/java/org/springframework/jmx/export/annotation/package-info.java @@ -3,4 +3,7 @@ * Hooked into Spring's JMX export infrastructure * via a special JmxAttributeSource implementation. */ +@NonNullApi package org.springframework.jmx.export.annotation; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context/src/main/java/org/springframework/jmx/export/assembler/AbstractReflectiveMBeanInfoAssembler.java b/spring-context/src/main/java/org/springframework/jmx/export/assembler/AbstractReflectiveMBeanInfoAssembler.java index f2d95bfa22..a600ae2980 100644 --- a/spring-context/src/main/java/org/springframework/jmx/export/assembler/AbstractReflectiveMBeanInfoAssembler.java +++ b/spring-context/src/main/java/org/springframework/jmx/export/assembler/AbstractReflectiveMBeanInfoAssembler.java @@ -33,6 +33,7 @@ import org.springframework.beans.BeanUtils; import org.springframework.core.DefaultParameterNameDiscoverer; import org.springframework.core.ParameterNameDiscoverer; import org.springframework.jmx.support.JmxUtils; +import org.springframework.lang.Nullable; /** * Builds on the {@link AbstractMBeanInfoAssembler} superclass to @@ -210,6 +211,7 @@ public abstract class AbstractReflectiveMBeanInfoAssembler extends AbstractMBean /** * Return default value for the JMX field "currencyTimeLimit", if any. */ + @Nullable protected Integer getDefaultCurrencyTimeLimit() { return this.defaultCurrencyTimeLimit; } @@ -272,6 +274,7 @@ public abstract class AbstractReflectiveMBeanInfoAssembler extends AbstractMBean * Return the ParameterNameDiscoverer to use for resolving method parameter * names if needed (may be {@code null} in order to skip parameter detection). */ + @Nullable protected ParameterNameDiscoverer getParameterNameDiscoverer() { return this.parameterNameDiscoverer; } diff --git a/spring-context/src/main/java/org/springframework/jmx/export/assembler/package-info.java b/spring-context/src/main/java/org/springframework/jmx/export/assembler/package-info.java index 649b1f97b5..a708f600e4 100644 --- a/spring-context/src/main/java/org/springframework/jmx/export/assembler/package-info.java +++ b/spring-context/src/main/java/org/springframework/jmx/export/assembler/package-info.java @@ -2,4 +2,7 @@ * Provides a strategy for MBeanInfo assembly. Used by MBeanExporter to * determine the attributes and operations to expose for Spring-managed beans. */ +@NonNullApi package org.springframework.jmx.export.assembler; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context/src/main/java/org/springframework/jmx/export/metadata/JmxAttributeSource.java b/spring-context/src/main/java/org/springframework/jmx/export/metadata/JmxAttributeSource.java index 8861079de2..aea8582956 100644 --- a/spring-context/src/main/java/org/springframework/jmx/export/metadata/JmxAttributeSource.java +++ b/spring-context/src/main/java/org/springframework/jmx/export/metadata/JmxAttributeSource.java @@ -18,6 +18,8 @@ package org.springframework.jmx.export.metadata; import java.lang.reflect.Method; +import org.springframework.lang.Nullable; + /** * Interface used by the {@code MetadataMBeanInfoAssembler} to * read source-level metadata from a managed resource's class. @@ -38,6 +40,7 @@ public interface JmxAttributeSource { * @return the attribute, or {@code null} if not found * @throws InvalidMetadataException in case of invalid attributes */ + @Nullable ManagedResource getManagedResource(Class clazz) throws InvalidMetadataException; /** @@ -48,6 +51,7 @@ public interface JmxAttributeSource { * @return the attribute, or {@code null} if not found * @throws InvalidMetadataException in case of invalid attributes */ + @Nullable ManagedAttribute getManagedAttribute(Method method) throws InvalidMetadataException; /** @@ -58,6 +62,7 @@ public interface JmxAttributeSource { * @return the metric, or {@code null} if not found * @throws InvalidMetadataException in case of invalid attributes */ + @Nullable ManagedMetric getManagedMetric(Method method) throws InvalidMetadataException; /** @@ -68,6 +73,7 @@ public interface JmxAttributeSource { * @return the attribute, or {@code null} if not found * @throws InvalidMetadataException in case of invalid attributes */ + @Nullable ManagedOperation getManagedOperation(Method method) throws InvalidMetadataException; /** diff --git a/spring-context/src/main/java/org/springframework/jmx/export/metadata/package-info.java b/spring-context/src/main/java/org/springframework/jmx/export/metadata/package-info.java index 8890cbda66..0eeca29333 100644 --- a/spring-context/src/main/java/org/springframework/jmx/export/metadata/package-info.java +++ b/spring-context/src/main/java/org/springframework/jmx/export/metadata/package-info.java @@ -2,4 +2,7 @@ * Provides generic JMX metadata classes and basic support for reading * JMX metadata in a provider-agnostic manner. */ +@NonNullApi package org.springframework.jmx.export.metadata; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context/src/main/java/org/springframework/jmx/export/naming/package-info.java b/spring-context/src/main/java/org/springframework/jmx/export/naming/package-info.java index f01f25f8da..f64aec45cc 100644 --- a/spring-context/src/main/java/org/springframework/jmx/export/naming/package-info.java +++ b/spring-context/src/main/java/org/springframework/jmx/export/naming/package-info.java @@ -2,4 +2,7 @@ * Provides a strategy for ObjectName creation. Used by MBeanExporter * to determine the JMX names to use for exported Spring-managed beans. */ +@NonNullApi package org.springframework.jmx.export.naming; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context/src/main/java/org/springframework/jmx/export/notification/package-info.java b/spring-context/src/main/java/org/springframework/jmx/export/notification/package-info.java index c0bd0a5b5c..3cedf29c04 100644 --- a/spring-context/src/main/java/org/springframework/jmx/export/notification/package-info.java +++ b/spring-context/src/main/java/org/springframework/jmx/export/notification/package-info.java @@ -2,4 +2,7 @@ * Provides supporting infrastructure to allow Spring-created MBeans * to send JMX notifications. */ +@NonNullApi package org.springframework.jmx.export.notification; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context/src/main/java/org/springframework/jmx/export/package-info.java b/spring-context/src/main/java/org/springframework/jmx/export/package-info.java index 1e27730635..a3a6347719 100644 --- a/spring-context/src/main/java/org/springframework/jmx/export/package-info.java +++ b/spring-context/src/main/java/org/springframework/jmx/export/package-info.java @@ -2,4 +2,7 @@ * This package provides declarative creation and registration of * Spring-managed beans as JMX MBeans. */ +@NonNullApi package org.springframework.jmx.export; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context/src/main/java/org/springframework/jmx/package-info.java b/spring-context/src/main/java/org/springframework/jmx/package-info.java index 2f95f65423..f300a243cc 100644 --- a/spring-context/src/main/java/org/springframework/jmx/package-info.java +++ b/spring-context/src/main/java/org/springframework/jmx/package-info.java @@ -2,4 +2,7 @@ * This package contains Spring's JMX support, which includes registration of * Spring-managed beans as JMX MBeans as well as access to remote JMX MBeans. */ +@NonNullApi package org.springframework.jmx; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context/src/main/java/org/springframework/jmx/support/JmxUtils.java b/spring-context/src/main/java/org/springframework/jmx/support/JmxUtils.java index 6b37279977..8410bb6072 100644 --- a/spring-context/src/main/java/org/springframework/jmx/support/JmxUtils.java +++ b/spring-context/src/main/java/org/springframework/jmx/support/JmxUtils.java @@ -33,6 +33,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.jmx.MBeanServerNotFoundException; +import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; @@ -88,7 +89,7 @@ public abstract class JmxUtils { * if no {@code MBeanServer} could be found * @see javax.management.MBeanServerFactory#findMBeanServer(String) */ - public static MBeanServer locateMBeanServer(String agentId) throws MBeanServerNotFoundException { + public static MBeanServer locateMBeanServer(@Nullable String agentId) throws MBeanServerNotFoundException { MBeanServer server = null; // null means any registered server, but "" specifically means the platform server @@ -267,6 +268,7 @@ public abstract class JmxUtils { * @param clazz the class to check * @return the Standard MBean interface for the given class */ + @Nullable public static Class getMBeanInterface(Class clazz) { if (clazz == null || clazz.getSuperclass() == null) { return null; @@ -288,6 +290,7 @@ public abstract class JmxUtils { * @param clazz the class to check * @return whether there is an MXBean interface for the given class */ + @Nullable public static Class getMXBeanInterface(Class clazz) { if (clazz == null || clazz.getSuperclass() == null) { return null; diff --git a/spring-context/src/main/java/org/springframework/jmx/support/MBeanServerFactoryBean.java b/spring-context/src/main/java/org/springframework/jmx/support/MBeanServerFactoryBean.java index 9bbfe08c85..0639aa87d9 100644 --- a/spring-context/src/main/java/org/springframework/jmx/support/MBeanServerFactoryBean.java +++ b/spring-context/src/main/java/org/springframework/jmx/support/MBeanServerFactoryBean.java @@ -26,6 +26,7 @@ import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.InitializingBean; import org.springframework.jmx.MBeanServerNotFoundException; +import org.springframework.lang.Nullable; /** * {@link FactoryBean} that obtains an {@link javax.management.MBeanServer} reference @@ -157,7 +158,7 @@ public class MBeanServerFactoryBean implements FactoryBean, Initial * @see JmxUtils#locateMBeanServer(String) * @see javax.management.MBeanServerFactory#findMBeanServer(String) */ - protected MBeanServer locateMBeanServer(String agentId) throws MBeanServerNotFoundException { + protected MBeanServer locateMBeanServer(@Nullable String agentId) throws MBeanServerNotFoundException { return JmxUtils.locateMBeanServer(agentId); } @@ -170,7 +171,7 @@ public class MBeanServerFactoryBean implements FactoryBean, Initial * @see javax.management.MBeanServerFactory#createMBeanServer * @see javax.management.MBeanServerFactory#newMBeanServer */ - protected MBeanServer createMBeanServer(String defaultDomain, boolean registerWithFactory) { + protected MBeanServer createMBeanServer(@Nullable String defaultDomain, boolean registerWithFactory) { if (registerWithFactory) { return MBeanServerFactory.createMBeanServer(defaultDomain); } diff --git a/spring-context/src/main/java/org/springframework/jmx/support/NotificationListenerHolder.java b/spring-context/src/main/java/org/springframework/jmx/support/NotificationListenerHolder.java index c40fd00972..6a0a6dd332 100644 --- a/spring-context/src/main/java/org/springframework/jmx/support/NotificationListenerHolder.java +++ b/spring-context/src/main/java/org/springframework/jmx/support/NotificationListenerHolder.java @@ -24,6 +24,7 @@ import javax.management.NotificationFilter; import javax.management.NotificationListener; import javax.management.ObjectName; +import org.springframework.lang.Nullable; import org.springframework.util.ObjectUtils; /** @@ -67,7 +68,7 @@ public class NotificationListenerHolder { * with the encapsulated {@link #getNotificationFilter() NotificationFilter}. *

May be {@code null}. */ - public void setNotificationFilter(NotificationFilter notificationFilter) { + public void setNotificationFilter(@Nullable NotificationFilter notificationFilter) { this.notificationFilter = notificationFilter; } @@ -76,6 +77,7 @@ public class NotificationListenerHolder { * with the encapsulated {@link #getNotificationFilter() NotificationFilter}. *

May be {@code null}. */ + @Nullable public NotificationFilter getNotificationFilter() { return this.notificationFilter; } @@ -87,7 +89,7 @@ public class NotificationListenerHolder { * @param handback the handback object (can be {@code null}) * @see javax.management.NotificationListener#handleNotification(javax.management.Notification, Object) */ - public void setHandback(Object handback) { + public void setHandback(@Nullable Object handback) { this.handback = handback; } @@ -98,6 +100,7 @@ public class NotificationListenerHolder { * @return the handback object (may be {@code null}) * @see javax.management.NotificationListener#handleNotification(javax.management.Notification, Object) */ + @Nullable public Object getHandback() { return this.handback; } diff --git a/spring-context/src/main/java/org/springframework/jmx/support/package-info.java b/spring-context/src/main/java/org/springframework/jmx/support/package-info.java index 56a389e6cc..1e9aeb5337 100644 --- a/spring-context/src/main/java/org/springframework/jmx/support/package-info.java +++ b/spring-context/src/main/java/org/springframework/jmx/support/package-info.java @@ -2,4 +2,7 @@ * Contains support classes for connecting to local and remote {@code MBeanServer}s * and for exposing an {@code MBeanServer} to remote clients. */ +@NonNullApi package org.springframework.jmx.support; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context/src/main/java/org/springframework/jndi/JndiCallback.java b/spring-context/src/main/java/org/springframework/jndi/JndiCallback.java index c6c76826f7..48f795e831 100644 --- a/spring-context/src/main/java/org/springframework/jndi/JndiCallback.java +++ b/spring-context/src/main/java/org/springframework/jndi/JndiCallback.java @@ -19,6 +19,8 @@ package org.springframework.jndi; import javax.naming.Context; import javax.naming.NamingException; +import org.springframework.lang.Nullable; + /** * Callback interface to be implemented by classes that need to perform an * operation (such as a lookup) in a JNDI context. This callback approach @@ -44,6 +46,7 @@ public interface JndiCallback { * @throws NamingException if thrown by JNDI methods * @return a result object, or {@code null} */ + @Nullable T doInContext(Context ctx) throws NamingException; } diff --git a/spring-context/src/main/java/org/springframework/jndi/JndiObjectLocator.java b/spring-context/src/main/java/org/springframework/jndi/JndiObjectLocator.java index bcf442ac0f..2adbceb8a0 100644 --- a/spring-context/src/main/java/org/springframework/jndi/JndiObjectLocator.java +++ b/spring-context/src/main/java/org/springframework/jndi/JndiObjectLocator.java @@ -19,6 +19,7 @@ package org.springframework.jndi; import javax.naming.NamingException; import org.springframework.beans.factory.InitializingBean; +import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; /** @@ -81,6 +82,7 @@ public abstract class JndiObjectLocator extends JndiLocatorSupport implements In * Return the type that the located JNDI object is supposed * to be assignable to, if any. */ + @Nullable public Class getExpectedType() { return this.expectedType; } diff --git a/spring-context/src/main/java/org/springframework/jndi/JndiTemplate.java b/spring-context/src/main/java/org/springframework/jndi/JndiTemplate.java index 3cec10527d..a1f1acfe39 100644 --- a/spring-context/src/main/java/org/springframework/jndi/JndiTemplate.java +++ b/spring-context/src/main/java/org/springframework/jndi/JndiTemplate.java @@ -26,6 +26,7 @@ import javax.naming.NamingException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; /** @@ -69,6 +70,7 @@ public class JndiTemplate { /** * Return the environment for the JNDI InitialContext, if any. */ + @Nullable public Properties getEnvironment() { return this.environment; } @@ -81,6 +83,7 @@ public class JndiTemplate { * @throws NamingException thrown by the callback implementation * @see #createInitialContext */ + @Nullable public T execute(JndiCallback contextCallback) throws NamingException { Context ctx = getContext(); try { @@ -108,7 +111,7 @@ public class JndiTemplate { * @param ctx the JNDI context to release (may be {@code null}) * @see #getContext */ - public void releaseContext(Context ctx) { + public void releaseContext(@Nullable Context ctx) { if (ctx != null) { try { ctx.close(); @@ -175,7 +178,7 @@ public class JndiTemplate { * name bound to JNDI */ @SuppressWarnings("unchecked") - public T lookup(String name, Class requiredType) throws NamingException { + public T lookup(String name, @Nullable Class requiredType) throws NamingException { Object jndiObject = lookup(name); if (requiredType != null && !requiredType.isInstance(jndiObject)) { throw new TypeMismatchNamingException( diff --git a/spring-context/src/main/java/org/springframework/jndi/package-info.java b/spring-context/src/main/java/org/springframework/jndi/package-info.java index 55bbba27ce..259a4f9a48 100644 --- a/spring-context/src/main/java/org/springframework/jndi/package-info.java +++ b/spring-context/src/main/java/org/springframework/jndi/package-info.java @@ -7,4 +7,7 @@ * Expert One-On-One J2EE Design and Development * by Rod Johnson (Wrox, 2002). */ +@NonNullApi package org.springframework.jndi; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context/src/main/java/org/springframework/jndi/support/package-info.java b/spring-context/src/main/java/org/springframework/jndi/support/package-info.java index 079a7677ad..2654ad32bf 100644 --- a/spring-context/src/main/java/org/springframework/jndi/support/package-info.java +++ b/spring-context/src/main/java/org/springframework/jndi/support/package-info.java @@ -2,4 +2,7 @@ * Support classes for JNDI usage, * including a JNDI-based BeanFactory implementation. */ +@NonNullApi package org.springframework.jndi.support; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context/src/main/java/org/springframework/remoting/package-info.java b/spring-context/src/main/java/org/springframework/remoting/package-info.java index 34c7601a70..85517537a4 100644 --- a/spring-context/src/main/java/org/springframework/remoting/package-info.java +++ b/spring-context/src/main/java/org/springframework/remoting/package-info.java @@ -2,4 +2,7 @@ * Exception hierarchy for Spring's remoting infrastructure, * independent of any specific remote method invocation system. */ +@NonNullApi package org.springframework.remoting; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context/src/main/java/org/springframework/remoting/rmi/CodebaseAwareObjectInputStream.java b/spring-context/src/main/java/org/springframework/remoting/rmi/CodebaseAwareObjectInputStream.java index 4bc3d794dc..ffdc6bda1f 100644 --- a/spring-context/src/main/java/org/springframework/remoting/rmi/CodebaseAwareObjectInputStream.java +++ b/spring-context/src/main/java/org/springframework/remoting/rmi/CodebaseAwareObjectInputStream.java @@ -21,6 +21,7 @@ import java.io.InputStream; import java.rmi.server.RMIClassLoader; import org.springframework.core.ConfigurableObjectInputStream; +import org.springframework.lang.Nullable; /** * Special ObjectInputStream subclass that falls back to a specified codebase @@ -76,7 +77,7 @@ public class CodebaseAwareObjectInputStream extends ConfigurableObjectInputStrea * @see java.io.ObjectInputStream#ObjectInputStream(java.io.InputStream) */ public CodebaseAwareObjectInputStream( - InputStream in, ClassLoader classLoader, String codebaseUrl) throws IOException { + InputStream in, @Nullable ClassLoader classLoader, String codebaseUrl) throws IOException { super(in, classLoader); this.codebaseUrl = codebaseUrl; @@ -92,7 +93,7 @@ public class CodebaseAwareObjectInputStream extends ConfigurableObjectInputStrea * @see java.io.ObjectInputStream#ObjectInputStream(java.io.InputStream) */ public CodebaseAwareObjectInputStream( - InputStream in, ClassLoader classLoader, boolean acceptProxyClasses) throws IOException { + InputStream in, @Nullable ClassLoader classLoader, boolean acceptProxyClasses) throws IOException { super(in, classLoader, acceptProxyClasses); this.codebaseUrl = null; diff --git a/spring-context/src/main/java/org/springframework/remoting/rmi/JndiRmiClientInterceptor.java b/spring-context/src/main/java/org/springframework/remoting/rmi/JndiRmiClientInterceptor.java index 1b3e43c694..fc8c6f8dee 100644 --- a/spring-context/src/main/java/org/springframework/remoting/rmi/JndiRmiClientInterceptor.java +++ b/spring-context/src/main/java/org/springframework/remoting/rmi/JndiRmiClientInterceptor.java @@ -28,6 +28,7 @@ import org.aopalliance.intercept.MethodInvocation; import org.springframework.aop.support.AopUtils; import org.springframework.beans.factory.InitializingBean; import org.springframework.jndi.JndiObjectLocator; +import org.springframework.lang.Nullable; import org.springframework.remoting.RemoteConnectFailureException; import org.springframework.remoting.RemoteInvocationFailureException; import org.springframework.remoting.RemoteLookupFailureException; @@ -338,6 +339,7 @@ public class JndiRmiClientInterceptor extends JndiObjectLocator implements Metho * @throws Throwable in case of invocation failure * @see #invoke */ + @Nullable protected Object refreshAndRetry(MethodInvocation invocation) throws Throwable { Object freshStub; synchronized (this.stubMonitor) { @@ -358,6 +360,7 @@ public class JndiRmiClientInterceptor extends JndiObjectLocator implements Metho * @return the invocation result, if any * @throws Throwable in case of invocation failure */ + @Nullable protected Object doInvoke(MethodInvocation invocation, Object stub) throws Throwable { if (stub instanceof RmiInvocationHandler) { // RMI invoker diff --git a/spring-context/src/main/java/org/springframework/remoting/rmi/RmiClientInterceptor.java b/spring-context/src/main/java/org/springframework/remoting/rmi/RmiClientInterceptor.java index b9e5330a17..829a18546b 100644 --- a/spring-context/src/main/java/org/springframework/remoting/rmi/RmiClientInterceptor.java +++ b/spring-context/src/main/java/org/springframework/remoting/rmi/RmiClientInterceptor.java @@ -34,6 +34,7 @@ import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; import org.springframework.aop.support.AopUtils; +import org.springframework.lang.Nullable; import org.springframework.remoting.RemoteConnectFailureException; import org.springframework.remoting.RemoteInvocationFailureException; import org.springframework.remoting.RemoteLookupFailureException; @@ -295,6 +296,7 @@ public class RmiClientInterceptor extends RemoteInvocationBasedAccessor * @see #setRefreshStubOnConnectFailure * @see #doInvoke */ + @Nullable private Object handleRemoteConnectFailure(MethodInvocation invocation, Exception ex) throws Throwable { if (this.refreshStubOnConnectFailure) { String msg = "Could not connect to RMI service [" + getServiceUrl() + "] - retrying"; @@ -319,6 +321,7 @@ public class RmiClientInterceptor extends RemoteInvocationBasedAccessor * @throws Throwable in case of invocation failure * @see #invoke */ + @Nullable protected Object refreshAndRetry(MethodInvocation invocation) throws Throwable { Remote freshStub = null; synchronized (this.stubMonitor) { @@ -338,6 +341,7 @@ public class RmiClientInterceptor extends RemoteInvocationBasedAccessor * @return the invocation result, if any * @throws Throwable in case of invocation failure */ + @Nullable protected Object doInvoke(MethodInvocation invocation, Remote stub) throws Throwable { if (stub instanceof RmiInvocationHandler) { // RMI invoker @@ -389,6 +393,7 @@ public class RmiClientInterceptor extends RemoteInvocationBasedAccessor * @throws InvocationTargetException if the method invocation resulted in an exception * @see org.springframework.remoting.support.RemoteInvocation */ + @Nullable protected Object doInvoke(MethodInvocation methodInvocation, RmiInvocationHandler invocationHandler) throws RemoteException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { diff --git a/spring-context/src/main/java/org/springframework/remoting/rmi/RmiClientInterceptorUtils.java b/spring-context/src/main/java/org/springframework/remoting/rmi/RmiClientInterceptorUtils.java index 4ee08b5d3b..af69edef55 100644 --- a/spring-context/src/main/java/org/springframework/remoting/rmi/RmiClientInterceptorUtils.java +++ b/spring-context/src/main/java/org/springframework/remoting/rmi/RmiClientInterceptorUtils.java @@ -30,6 +30,7 @@ import org.aopalliance.intercept.MethodInvocation; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.lang.Nullable; import org.springframework.remoting.RemoteAccessException; import org.springframework.remoting.RemoteConnectFailureException; import org.springframework.remoting.RemoteProxyFailureException; @@ -57,6 +58,7 @@ public abstract class RmiClientInterceptorUtils { * @return the invocation result, if any * @throws InvocationTargetException if thrown by reflection */ + @Nullable public static Object invokeRemoteMethod(MethodInvocation invocation, Object stub) throws InvocationTargetException { diff --git a/spring-context/src/main/java/org/springframework/remoting/rmi/RmiInvocationHandler.java b/spring-context/src/main/java/org/springframework/remoting/rmi/RmiInvocationHandler.java index 77ddbaf44f..bdbcd184fc 100644 --- a/spring-context/src/main/java/org/springframework/remoting/rmi/RmiInvocationHandler.java +++ b/spring-context/src/main/java/org/springframework/remoting/rmi/RmiInvocationHandler.java @@ -20,6 +20,7 @@ import java.lang.reflect.InvocationTargetException; import java.rmi.Remote; import java.rmi.RemoteException; +import org.springframework.lang.Nullable; import org.springframework.remoting.support.RemoteInvocation; /** @@ -40,6 +41,7 @@ public interface RmiInvocationHandler extends Remote { * @throws RemoteException in case of communication errors * @see RmiServiceExporter#getServiceInterface() */ + @Nullable public String getTargetInterfaceName() throws RemoteException; /** @@ -53,6 +55,7 @@ public interface RmiInvocationHandler extends Remote { * @throws IllegalAccessException if the method could not be accessed * @throws InvocationTargetException if the method invocation resulted in an exception */ + @Nullable public Object invoke(RemoteInvocation invocation) throws RemoteException, NoSuchMethodException, IllegalAccessException, InvocationTargetException; diff --git a/spring-context/src/main/java/org/springframework/remoting/rmi/RmiRegistryFactoryBean.java b/spring-context/src/main/java/org/springframework/remoting/rmi/RmiRegistryFactoryBean.java index b7107934b3..8833b8e070 100644 --- a/spring-context/src/main/java/org/springframework/remoting/rmi/RmiRegistryFactoryBean.java +++ b/spring-context/src/main/java/org/springframework/remoting/rmi/RmiRegistryFactoryBean.java @@ -29,6 +29,7 @@ import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.InitializingBean; +import org.springframework.lang.Nullable; /** * {@link FactoryBean} that locates a {@link java.rmi.registry.Registry} and @@ -177,7 +178,7 @@ public class RmiRegistryFactoryBean implements FactoryBean, Initializi * @throws java.rmi.RemoteException if the registry couldn't be located or created */ protected Registry getRegistry(String registryHost, int registryPort, - RMIClientSocketFactory clientSocketFactory, RMIServerSocketFactory serverSocketFactory) + @Nullable RMIClientSocketFactory clientSocketFactory, @Nullable RMIServerSocketFactory serverSocketFactory) throws RemoteException { if (registryHost != null) { @@ -203,8 +204,8 @@ public class RmiRegistryFactoryBean implements FactoryBean, Initializi * @return the RMI registry * @throws RemoteException if the registry couldn't be located or created */ - protected Registry getRegistry( - int registryPort, RMIClientSocketFactory clientSocketFactory, RMIServerSocketFactory serverSocketFactory) + protected Registry getRegistry(int registryPort, + @Nullable RMIClientSocketFactory clientSocketFactory, @Nullable RMIServerSocketFactory serverSocketFactory) throws RemoteException { if (clientSocketFactory != null) { diff --git a/spring-context/src/main/java/org/springframework/remoting/rmi/RmiServiceExporter.java b/spring-context/src/main/java/org/springframework/remoting/rmi/RmiServiceExporter.java index ca3f6e5f2e..960fc466b5 100644 --- a/spring-context/src/main/java/org/springframework/remoting/rmi/RmiServiceExporter.java +++ b/spring-context/src/main/java/org/springframework/remoting/rmi/RmiServiceExporter.java @@ -29,6 +29,7 @@ import java.rmi.server.UnicastRemoteObject; import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.InitializingBean; +import org.springframework.lang.Nullable; /** * RMI exporter that exposes the specified service as RMI object with the specified name. @@ -319,7 +320,7 @@ public class RmiServiceExporter extends RmiBasedExporter implements Initializing * @throws RemoteException if the registry couldn't be located or created */ protected Registry getRegistry(String registryHost, int registryPort, - RMIClientSocketFactory clientSocketFactory, RMIServerSocketFactory serverSocketFactory) + @Nullable RMIClientSocketFactory clientSocketFactory, @Nullable RMIServerSocketFactory serverSocketFactory) throws RemoteException { if (registryHost != null) { @@ -345,8 +346,8 @@ public class RmiServiceExporter extends RmiBasedExporter implements Initializing * @return the RMI registry * @throws RemoteException if the registry couldn't be located or created */ - protected Registry getRegistry( - int registryPort, RMIClientSocketFactory clientSocketFactory, RMIServerSocketFactory serverSocketFactory) + protected Registry getRegistry(int registryPort, + @Nullable RMIClientSocketFactory clientSocketFactory, @Nullable RMIServerSocketFactory serverSocketFactory) throws RemoteException { if (clientSocketFactory != null) { diff --git a/spring-context/src/main/java/org/springframework/remoting/support/RemoteInvocation.java b/spring-context/src/main/java/org/springframework/remoting/support/RemoteInvocation.java index 3d8ebba918..e868f21210 100644 --- a/spring-context/src/main/java/org/springframework/remoting/support/RemoteInvocation.java +++ b/spring-context/src/main/java/org/springframework/remoting/support/RemoteInvocation.java @@ -24,6 +24,7 @@ import java.util.Map; import org.aopalliance.intercept.MethodInvocation; +import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; /** @@ -165,6 +166,7 @@ public class RemoteInvocation implements Serializable { * @param key the attribute key * @return the attribute value, or {@code null} if not defined */ + @Nullable public Serializable getAttribute(String key) { if (this.attributes == null) { return null; @@ -190,6 +192,7 @@ public class RemoteInvocation implements Serializable { * @see #addAttribute * @see #getAttribute */ + @Nullable public Map getAttributes() { return this.attributes; } diff --git a/spring-context/src/main/java/org/springframework/remoting/support/RemoteInvocationResult.java b/spring-context/src/main/java/org/springframework/remoting/support/RemoteInvocationResult.java index e9dee2f72b..8e7ef09fab 100644 --- a/spring-context/src/main/java/org/springframework/remoting/support/RemoteInvocationResult.java +++ b/spring-context/src/main/java/org/springframework/remoting/support/RemoteInvocationResult.java @@ -19,6 +19,8 @@ package org.springframework.remoting.support; import java.io.Serializable; import java.lang.reflect.InvocationTargetException; +import org.springframework.lang.Nullable; + /** * Encapsulates a remote invocation result, holding a result value or an exception. * Used for HTTP-based serialization invokers. @@ -88,6 +90,7 @@ public class RemoteInvocationResult implements Serializable { * of the target method, if any. * @see #hasException */ + @Nullable public Object getValue() { return this.value; } @@ -108,6 +111,7 @@ public class RemoteInvocationResult implements Serializable { * of the target method, if any. * @see #hasException */ + @Nullable public Throwable getException() { return this.exception; } @@ -140,6 +144,7 @@ public class RemoteInvocationResult implements Serializable { * @return the result value, if any * @throws Throwable the exception, if any */ + @Nullable public Object recreate() throws Throwable { if (this.exception != null) { Throwable exToThrow = this.exception; diff --git a/spring-context/src/main/java/org/springframework/remoting/support/RemotingSupport.java b/spring-context/src/main/java/org/springframework/remoting/support/RemotingSupport.java index 02f31ba803..4cae3f2188 100644 --- a/spring-context/src/main/java/org/springframework/remoting/support/RemotingSupport.java +++ b/spring-context/src/main/java/org/springframework/remoting/support/RemotingSupport.java @@ -20,6 +20,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.BeanClassLoaderAware; +import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; /** @@ -57,6 +58,7 @@ public abstract class RemotingSupport implements BeanClassLoaderAware { * context ClassLoader already. * @return the original thread context ClassLoader, or {@code null} if not overridden */ + @Nullable protected ClassLoader overrideThreadContextClassLoader() { return ClassUtils.overrideThreadContextClassLoader(getBeanClassLoader()); } @@ -66,7 +68,7 @@ public abstract class RemotingSupport implements BeanClassLoaderAware { * @param original the original thread context ClassLoader, * or {@code null} if not overridden (and hence nothing to reset) */ - protected void resetThreadContextClassLoader(ClassLoader original) { + protected void resetThreadContextClassLoader(@Nullable ClassLoader original) { if (original != null) { Thread.currentThread().setContextClassLoader(original); } diff --git a/spring-context/src/main/java/org/springframework/scheduling/TaskScheduler.java b/spring-context/src/main/java/org/springframework/scheduling/TaskScheduler.java index bf902e71db..51863793c7 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/TaskScheduler.java +++ b/spring-context/src/main/java/org/springframework/scheduling/TaskScheduler.java @@ -21,6 +21,8 @@ import java.time.Instant; import java.util.Date; import java.util.concurrent.ScheduledFuture; +import org.springframework.lang.Nullable; + /** * Task scheduler interface that abstracts the scheduling of * {@link Runnable Runnables} based on different kinds of triggers. @@ -63,6 +65,7 @@ public interface TaskScheduler { * for internal reasons (e.g. a pool overload handling policy or a pool shutdown in progress) * @see org.springframework.scheduling.support.CronTrigger */ + @Nullable ScheduledFuture schedule(Runnable task, Trigger trigger); /** diff --git a/spring-context/src/main/java/org/springframework/scheduling/Trigger.java b/spring-context/src/main/java/org/springframework/scheduling/Trigger.java index 4c8d9a1ed7..0211382493 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/Trigger.java +++ b/spring-context/src/main/java/org/springframework/scheduling/Trigger.java @@ -18,6 +18,8 @@ package org.springframework.scheduling; import java.util.Date; +import org.springframework.lang.Nullable; + /** * Common interface for trigger objects that determine the next execution time * of a task that they get associated with. @@ -36,6 +38,7 @@ public interface Trigger { * @return the next execution time as defined by the trigger, * or {@code null} if the trigger won't fire anymore */ + @Nullable Date nextExecutionTime(TriggerContext triggerContext); } diff --git a/spring-context/src/main/java/org/springframework/scheduling/TriggerContext.java b/spring-context/src/main/java/org/springframework/scheduling/TriggerContext.java index feeb2ecea6..38fce12392 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/TriggerContext.java +++ b/spring-context/src/main/java/org/springframework/scheduling/TriggerContext.java @@ -18,6 +18,8 @@ package org.springframework.scheduling; import java.util.Date; +import org.springframework.lang.Nullable; + /** * Context object encapsulating last execution times and last completion time * of a given task. @@ -31,18 +33,21 @@ public interface TriggerContext { * Return the last scheduled execution time of the task, * or {@code null} if not scheduled before. */ + @Nullable Date lastScheduledExecutionTime(); /** * Return the last actual execution time of the task, * or {@code null} if not scheduled before. */ + @Nullable Date lastActualExecutionTime(); /** * Return the last completion time of the task, * or {@code null} if not scheduled before. */ + @Nullable Date lastCompletionTime(); } diff --git a/spring-context/src/main/java/org/springframework/scheduling/annotation/AsyncAnnotationAdvisor.java b/spring-context/src/main/java/org/springframework/scheduling/annotation/AsyncAnnotationAdvisor.java index 15dea168d7..3a28f39066 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/annotation/AsyncAnnotationAdvisor.java +++ b/spring-context/src/main/java/org/springframework/scheduling/annotation/AsyncAnnotationAdvisor.java @@ -32,6 +32,7 @@ import org.springframework.aop.support.ComposablePointcut; import org.springframework.aop.support.annotation.AnnotationMatchingPointcut; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; @@ -76,7 +77,7 @@ public class AsyncAnnotationAdvisor extends AbstractPointcutAdvisor implements B * @see AnnotationAsyncExecutionInterceptor#getDefaultExecutor(BeanFactory) */ @SuppressWarnings("unchecked") - public AsyncAnnotationAdvisor(Executor executor, AsyncUncaughtExceptionHandler exceptionHandler) { + public AsyncAnnotationAdvisor(@Nullable Executor executor, AsyncUncaughtExceptionHandler exceptionHandler) { Set> asyncAnnotationTypes = new LinkedHashSet<>(2); asyncAnnotationTypes.add(Async.class); try { @@ -151,6 +152,7 @@ public class AsyncAnnotationAdvisor extends AbstractPointcutAdvisor implements B * @param asyncAnnotationTypes the async annotation types to introspect * @return the applicable Pointcut object, or {@code null} if none */ + @Nullable protected Pointcut buildPointcut(Set> asyncAnnotationTypes) { ComposablePointcut result = null; for (Class asyncAnnotationType : asyncAnnotationTypes) { diff --git a/spring-context/src/main/java/org/springframework/scheduling/annotation/package-info.java b/spring-context/src/main/java/org/springframework/scheduling/annotation/package-info.java index 318c8fbee8..1f38139ead 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/annotation/package-info.java +++ b/spring-context/src/main/java/org/springframework/scheduling/annotation/package-info.java @@ -1,4 +1,7 @@ /** * Java 5 annotation for asynchronous method execution. */ +@NonNullApi package org.springframework.scheduling.annotation; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context/src/main/java/org/springframework/scheduling/concurrent/ReschedulingRunnable.java b/spring-context/src/main/java/org/springframework/scheduling/concurrent/ReschedulingRunnable.java index 0a3e6ecdd9..b43d04ecbe 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/concurrent/ReschedulingRunnable.java +++ b/spring-context/src/main/java/org/springframework/scheduling/concurrent/ReschedulingRunnable.java @@ -24,6 +24,7 @@ import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; +import org.springframework.lang.Nullable; import org.springframework.scheduling.Trigger; import org.springframework.scheduling.support.DelegatingErrorHandlingRunnable; import org.springframework.scheduling.support.SimpleTriggerContext; @@ -63,6 +64,7 @@ class ReschedulingRunnable extends DelegatingErrorHandlingRunnable implements Sc } + @Nullable public ScheduledFuture schedule() { synchronized (this.triggerContextMonitor) { this.scheduledExecutionTime = this.trigger.nextExecutionTime(this.triggerContext); diff --git a/spring-context/src/main/java/org/springframework/scheduling/concurrent/package-info.java b/spring-context/src/main/java/org/springframework/scheduling/concurrent/package-info.java index 4077955958..bf23055e21 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/concurrent/package-info.java +++ b/spring-context/src/main/java/org/springframework/scheduling/concurrent/package-info.java @@ -5,4 +5,7 @@ * context. Provides support for the native {@code java.util.concurrent} * interfaces as well as the Spring {@code TaskExecutor} mechanism. */ +@NonNullApi package org.springframework.scheduling.concurrent; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context/src/main/java/org/springframework/scheduling/config/ScheduledTaskRegistrar.java b/spring-context/src/main/java/org/springframework/scheduling/config/ScheduledTaskRegistrar.java index a613c0b782..b1702be5ad 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/config/ScheduledTaskRegistrar.java +++ b/spring-context/src/main/java/org/springframework/scheduling/config/ScheduledTaskRegistrar.java @@ -29,6 +29,7 @@ import java.util.concurrent.ScheduledExecutorService; import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.InitializingBean; +import org.springframework.lang.Nullable; import org.springframework.scheduling.TaskScheduler; import org.springframework.scheduling.Trigger; import org.springframework.scheduling.concurrent.ConcurrentTaskScheduler; @@ -101,6 +102,7 @@ public class ScheduledTaskRegistrar implements InitializingBean, DisposableBean /** * Return the {@link TaskScheduler} instance for this registrar (may be {@code null}). */ + @Nullable public TaskScheduler getScheduler() { return this.taskScheduler; } @@ -398,6 +400,7 @@ public class ScheduledTaskRegistrar implements InitializingBean, DisposableBean * (or {@code null} if processing a previously registered task) * @since 4.3 */ + @Nullable public ScheduledTask scheduleCronTask(CronTask task) { ScheduledTask scheduledTask = this.unresolvedTasks.remove(task); boolean newTask = false; @@ -422,6 +425,7 @@ public class ScheduledTaskRegistrar implements InitializingBean, DisposableBean * (or {@code null} if processing a previously registered task) * @since 4.3 */ + @Nullable public ScheduledTask scheduleFixedRateTask(IntervalTask task) { ScheduledTask scheduledTask = this.unresolvedTasks.remove(task); boolean newTask = false; @@ -454,6 +458,7 @@ public class ScheduledTaskRegistrar implements InitializingBean, DisposableBean * (or {@code null} if processing a previously registered task) * @since 4.3 */ + @Nullable public ScheduledTask scheduleFixedDelayTask(IntervalTask task) { ScheduledTask scheduledTask = this.unresolvedTasks.remove(task); boolean newTask = false; diff --git a/spring-context/src/main/java/org/springframework/scheduling/config/package-info.java b/spring-context/src/main/java/org/springframework/scheduling/config/package-info.java index 65dac8fec3..8fdf7b700b 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/config/package-info.java +++ b/spring-context/src/main/java/org/springframework/scheduling/config/package-info.java @@ -2,4 +2,7 @@ * Support package for declarative scheduling configuration, * with XML schema being the primary configuration format. */ +@NonNullApi package org.springframework.scheduling.config; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context/src/main/java/org/springframework/scheduling/package-info.java b/spring-context/src/main/java/org/springframework/scheduling/package-info.java index 22dd462809..6ae921bb0e 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/package-info.java +++ b/spring-context/src/main/java/org/springframework/scheduling/package-info.java @@ -2,4 +2,7 @@ * General exceptions for Spring's scheduling support, * independent of any specific scheduling system. */ +@NonNullApi package org.springframework.scheduling; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context/src/main/java/org/springframework/scheduling/support/TaskUtils.java b/spring-context/src/main/java/org/springframework/scheduling/support/TaskUtils.java index 3b86d2fbd2..22a7c74fe1 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/support/TaskUtils.java +++ b/spring-context/src/main/java/org/springframework/scheduling/support/TaskUtils.java @@ -21,6 +21,7 @@ import java.util.concurrent.Future; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.lang.Nullable; import org.springframework.util.ErrorHandler; import org.springframework.util.ReflectionUtils; @@ -60,7 +61,7 @@ public abstract class TaskUtils { * returned {@link Future}. In both cases, the errors will be logged. */ public static DelegatingErrorHandlingRunnable decorateTaskWithErrorHandler( - Runnable task, ErrorHandler errorHandler, boolean isRepeatingTask) { + Runnable task, @Nullable ErrorHandler errorHandler, boolean isRepeatingTask) { if (task instanceof DelegatingErrorHandlingRunnable) { return (DelegatingErrorHandlingRunnable) task; diff --git a/spring-context/src/main/java/org/springframework/scheduling/support/package-info.java b/spring-context/src/main/java/org/springframework/scheduling/support/package-info.java index 25b09fb0d7..d1bc1cefff 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/support/package-info.java +++ b/spring-context/src/main/java/org/springframework/scheduling/support/package-info.java @@ -2,4 +2,7 @@ * Generic support classes for scheduling. * Provides a Runnable adapter for Spring's MethodInvoker. */ +@NonNullApi package org.springframework.scheduling.support; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context/src/main/java/org/springframework/scripting/ScriptCompilationException.java b/spring-context/src/main/java/org/springframework/scripting/ScriptCompilationException.java index 2064ae9080..ec0660be0b 100644 --- a/spring-context/src/main/java/org/springframework/scripting/ScriptCompilationException.java +++ b/spring-context/src/main/java/org/springframework/scripting/ScriptCompilationException.java @@ -17,6 +17,7 @@ package org.springframework.scripting; import org.springframework.core.NestedRuntimeException; +import org.springframework.lang.Nullable; /** * Exception to be thrown on script compilation failure. @@ -84,6 +85,7 @@ public class ScriptCompilationException extends NestedRuntimeException { * Return the source for the offending script. * @return the source, or {@code null} if not available */ + @Nullable public ScriptSource getScriptSource() { return this.scriptSource; } diff --git a/spring-context/src/main/java/org/springframework/scripting/ScriptEvaluator.java b/spring-context/src/main/java/org/springframework/scripting/ScriptEvaluator.java index 918877c4e5..35b150dd8b 100644 --- a/spring-context/src/main/java/org/springframework/scripting/ScriptEvaluator.java +++ b/spring-context/src/main/java/org/springframework/scripting/ScriptEvaluator.java @@ -18,6 +18,8 @@ package org.springframework.scripting; import java.util.Map; +import org.springframework.lang.Nullable; + /** * Spring's strategy interface for evaluating a script. * @@ -38,6 +40,7 @@ public interface ScriptEvaluator { * @throws ScriptCompilationException if the evaluator failed to read, * compile or evaluate the script */ + @Nullable Object evaluate(ScriptSource script) throws ScriptCompilationException; /** @@ -49,6 +52,7 @@ public interface ScriptEvaluator { * @throws ScriptCompilationException if the evaluator failed to read, * compile or evaluate the script */ - Object evaluate(ScriptSource script, Map arguments) throws ScriptCompilationException; + @Nullable + Object evaluate(ScriptSource script, @Nullable Map arguments) throws ScriptCompilationException; } diff --git a/spring-context/src/main/java/org/springframework/scripting/ScriptFactory.java b/spring-context/src/main/java/org/springframework/scripting/ScriptFactory.java index dc835a60ff..f4cb808ebf 100644 --- a/spring-context/src/main/java/org/springframework/scripting/ScriptFactory.java +++ b/spring-context/src/main/java/org/springframework/scripting/ScriptFactory.java @@ -18,6 +18,8 @@ package org.springframework.scripting; import java.io.IOException; +import org.springframework.lang.Nullable; + /** * Script definition interface, encapsulating the configuration * of a specific script as well as a factory method for @@ -49,6 +51,7 @@ public interface ScriptFactory { * its Java interfaces (such as in the case of Groovy). * @return the interfaces for the script */ + @Nullable Class[] getScriptInterfaces(); /** @@ -75,7 +78,7 @@ public interface ScriptFactory { * @throws IOException if script retrieval failed * @throws ScriptCompilationException if script compilation failed */ - Object getScriptedObject(ScriptSource scriptSource, Class... actualInterfaces) + Object getScriptedObject(ScriptSource scriptSource, @Nullable Class... actualInterfaces) throws IOException, ScriptCompilationException; /** @@ -91,6 +94,7 @@ public interface ScriptFactory { * @throws ScriptCompilationException if script compilation failed * @since 2.0.3 */ + @Nullable Class getScriptedObjectType(ScriptSource scriptSource) throws IOException, ScriptCompilationException; diff --git a/spring-context/src/main/java/org/springframework/scripting/ScriptSource.java b/spring-context/src/main/java/org/springframework/scripting/ScriptSource.java index 2e5a37e4d4..2e13af6b10 100644 --- a/spring-context/src/main/java/org/springframework/scripting/ScriptSource.java +++ b/spring-context/src/main/java/org/springframework/scripting/ScriptSource.java @@ -18,6 +18,8 @@ package org.springframework.scripting; import java.io.IOException; +import org.springframework.lang.Nullable; + /** * Interface that defines the source of a script. * Tracks whether the underlying script has been modified. @@ -47,6 +49,7 @@ public interface ScriptSource { * Determine a class name for the underlying script. * @return the suggested class name, or {@code null} if none available */ + @Nullable String suggestedClassName(); } diff --git a/spring-context/src/main/java/org/springframework/scripting/bsh/BshScriptFactory.java b/spring-context/src/main/java/org/springframework/scripting/bsh/BshScriptFactory.java index 86d87d354e..4f4b7710e0 100644 --- a/spring-context/src/main/java/org/springframework/scripting/bsh/BshScriptFactory.java +++ b/spring-context/src/main/java/org/springframework/scripting/bsh/BshScriptFactory.java @@ -21,6 +21,7 @@ import java.io.IOException; import bsh.EvalError; import org.springframework.beans.factory.BeanClassLoaderAware; +import org.springframework.lang.Nullable; import org.springframework.scripting.ScriptCompilationException; import org.springframework.scripting.ScriptFactory; import org.springframework.scripting.ScriptSource; @@ -81,7 +82,7 @@ public class BshScriptFactory implements ScriptFactory, BeanClassLoaderAware { * @param scriptInterfaces the Java interfaces that the scripted object * is supposed to implement (may be {@code null}) */ - public BshScriptFactory(String scriptSourceLocator, Class... scriptInterfaces) { + public BshScriptFactory(String scriptSourceLocator, @Nullable Class... scriptInterfaces) { Assert.hasText(scriptSourceLocator, "'scriptSourceLocator' must not be empty"); this.scriptSourceLocator = scriptSourceLocator; this.scriptInterfaces = scriptInterfaces; diff --git a/spring-context/src/main/java/org/springframework/scripting/bsh/BshScriptUtils.java b/spring-context/src/main/java/org/springframework/scripting/bsh/BshScriptUtils.java index f7f634df2c..7ebc36b192 100644 --- a/spring-context/src/main/java/org/springframework/scripting/bsh/BshScriptUtils.java +++ b/spring-context/src/main/java/org/springframework/scripting/bsh/BshScriptUtils.java @@ -26,6 +26,7 @@ import bsh.Primitive; import bsh.XThis; import org.springframework.core.NestedRuntimeException; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.ReflectionUtils; @@ -66,7 +67,7 @@ public abstract class BshScriptUtils { * @throws EvalError in case of BeanShell parsing failure * @see #createBshObject(String, Class[], ClassLoader) */ - public static Object createBshObject(String scriptSource, Class... scriptInterfaces) throws EvalError { + public static Object createBshObject(String scriptSource, @Nullable Class... scriptInterfaces) throws EvalError { return createBshObject(scriptSource, scriptInterfaces, ClassUtils.getDefaultClassLoader()); } @@ -84,7 +85,7 @@ public abstract class BshScriptUtils { * @return the scripted Java object * @throws EvalError in case of BeanShell parsing failure */ - public static Object createBshObject(String scriptSource, Class[] scriptInterfaces, ClassLoader classLoader) + public static Object createBshObject(String scriptSource, @Nullable Class[] scriptInterfaces, ClassLoader classLoader) throws EvalError { Object result = evaluateBshScript(scriptSource, scriptInterfaces, classLoader); @@ -113,6 +114,7 @@ public abstract class BshScriptUtils { * @return the scripted Java class, or {@code null} if none could be determined * @throws EvalError in case of BeanShell parsing failure */ + @Nullable static Class determineBshObjectType(String scriptSource, ClassLoader classLoader) throws EvalError { Assert.hasText(scriptSource, "Script source must not be empty"); Interpreter interpreter = new Interpreter(); @@ -144,7 +146,7 @@ public abstract class BshScriptUtils { * @return the scripted Java class or Java object * @throws EvalError in case of BeanShell parsing failure */ - static Object evaluateBshScript(String scriptSource, Class[] scriptInterfaces, ClassLoader classLoader) + static Object evaluateBshScript(String scriptSource, @Nullable Class[] scriptInterfaces, ClassLoader classLoader) throws EvalError { Assert.hasText(scriptSource, "Script source must not be empty"); @@ -176,6 +178,7 @@ public abstract class BshScriptUtils { } @Override + @Nullable public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if (ReflectionUtils.isEqualsMethod(method)) { return (isProxyForSameBshObject(args[0])); diff --git a/spring-context/src/main/java/org/springframework/scripting/bsh/package-info.java b/spring-context/src/main/java/org/springframework/scripting/bsh/package-info.java index a8adbca6c9..9ac76f5b11 100644 --- a/spring-context/src/main/java/org/springframework/scripting/bsh/package-info.java +++ b/spring-context/src/main/java/org/springframework/scripting/bsh/package-info.java @@ -4,4 +4,7 @@ * (and BeanShell2) * into Spring's scripting infrastructure. */ +@NonNullApi package org.springframework.scripting.bsh; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context/src/main/java/org/springframework/scripting/config/ScriptBeanDefinitionParser.java b/spring-context/src/main/java/org/springframework/scripting/config/ScriptBeanDefinitionParser.java index 159e0aa108..70f026bf00 100644 --- a/spring-context/src/main/java/org/springframework/scripting/config/ScriptBeanDefinitionParser.java +++ b/spring-context/src/main/java/org/springframework/scripting/config/ScriptBeanDefinitionParser.java @@ -29,6 +29,7 @@ import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser; import org.springframework.beans.factory.xml.BeanDefinitionParserDelegate; import org.springframework.beans.factory.xml.ParserContext; import org.springframework.beans.factory.xml.XmlReaderContext; +import org.springframework.lang.Nullable; import org.springframework.scripting.support.ScriptFactoryPostProcessor; import org.springframework.util.StringUtils; import org.springframework.util.xml.DomUtils; @@ -213,6 +214,7 @@ class ScriptBeanDefinitionParser extends AbstractBeanDefinitionParser { * the '{@code inline-script}' element. Logs and {@link XmlReaderContext#error} and * returns {@code null} if neither or both of these values are specified. */ + @Nullable private String resolveScriptSource(Element element, XmlReaderContext readerContext) { boolean hasScriptSource = element.hasAttribute(SCRIPT_SOURCE_ATTRIBUTE); List elements = DomUtils.getChildElementsByTagName(element, INLINE_SCRIPT_ELEMENT); diff --git a/spring-context/src/main/java/org/springframework/scripting/config/package-info.java b/spring-context/src/main/java/org/springframework/scripting/config/package-info.java index c0747d0db3..6688a44389 100644 --- a/spring-context/src/main/java/org/springframework/scripting/config/package-info.java +++ b/spring-context/src/main/java/org/springframework/scripting/config/package-info.java @@ -2,4 +2,7 @@ * Support package for Spring's dynamic language machinery, * with XML schema being the primary configuration format. */ +@NonNullApi package org.springframework.scripting.config; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context/src/main/java/org/springframework/scripting/groovy/GroovyScriptFactory.java b/spring-context/src/main/java/org/springframework/scripting/groovy/GroovyScriptFactory.java index 4155b3f986..ba9faf6408 100644 --- a/spring-context/src/main/java/org/springframework/scripting/groovy/GroovyScriptFactory.java +++ b/spring-context/src/main/java/org/springframework/scripting/groovy/GroovyScriptFactory.java @@ -31,6 +31,7 @@ import org.springframework.beans.factory.BeanClassLoaderAware; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; +import org.springframework.lang.Nullable; import org.springframework.scripting.ScriptCompilationException; import org.springframework.scripting.ScriptFactory; import org.springframework.scripting.ScriptSource; @@ -100,7 +101,7 @@ public class GroovyScriptFactory implements ScriptFactory, BeanFactoryAware, Bea * (may be {@code null}) * @see GroovyObjectCustomizer#customize */ - public GroovyScriptFactory(String scriptSourceLocator, GroovyObjectCustomizer groovyObjectCustomizer) { + public GroovyScriptFactory(String scriptSourceLocator, @Nullable GroovyObjectCustomizer groovyObjectCustomizer) { this(scriptSourceLocator); this.groovyObjectCustomizer = groovyObjectCustomizer; } @@ -116,7 +117,7 @@ public class GroovyScriptFactory implements ScriptFactory, BeanFactoryAware, Bea * @since 4.3.3 * @see GroovyClassLoader#GroovyClassLoader(ClassLoader, CompilerConfiguration) */ - public GroovyScriptFactory(String scriptSourceLocator, CompilerConfiguration compilerConfiguration) { + public GroovyScriptFactory(String scriptSourceLocator, @Nullable CompilerConfiguration compilerConfiguration) { this(scriptSourceLocator); this.compilerConfiguration = compilerConfiguration; } diff --git a/spring-context/src/main/java/org/springframework/scripting/groovy/package-info.java b/spring-context/src/main/java/org/springframework/scripting/groovy/package-info.java index 47d7fa23d9..a8d72bb5ed 100644 --- a/spring-context/src/main/java/org/springframework/scripting/groovy/package-info.java +++ b/spring-context/src/main/java/org/springframework/scripting/groovy/package-info.java @@ -3,4 +3,7 @@ * Groovy * into Spring's scripting infrastructure. */ +@NonNullApi package org.springframework.scripting.groovy; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context/src/main/java/org/springframework/scripting/package-info.java b/spring-context/src/main/java/org/springframework/scripting/package-info.java index 64d0f935e1..cbbf0f1ee6 100644 --- a/spring-context/src/main/java/org/springframework/scripting/package-info.java +++ b/spring-context/src/main/java/org/springframework/scripting/package-info.java @@ -1,4 +1,7 @@ /** * Core interfaces for Spring's scripting support. */ +@NonNullApi package org.springframework.scripting; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context/src/main/java/org/springframework/scripting/support/ResourceScriptSource.java b/spring-context/src/main/java/org/springframework/scripting/support/ResourceScriptSource.java index 3e4c1df36b..0d19bb798a 100644 --- a/spring-context/src/main/java/org/springframework/scripting/support/ResourceScriptSource.java +++ b/spring-context/src/main/java/org/springframework/scripting/support/ResourceScriptSource.java @@ -24,6 +24,7 @@ import org.apache.commons.logging.LogFactory; import org.springframework.core.io.Resource; import org.springframework.core.io.support.EncodedResource; +import org.springframework.lang.Nullable; import org.springframework.scripting.ScriptSource; import org.springframework.util.Assert; import org.springframework.util.FileCopyUtils; @@ -88,7 +89,7 @@ public class ResourceScriptSource implements ScriptSource { *

The default value for regular Resources is "UTF-8". * A {@code null} value implies the platform default. */ - public void setEncoding(String encoding) { + public void setEncoding(@Nullable String encoding) { this.resource = new EncodedResource(this.resource.getResource(), encoding); } diff --git a/spring-context/src/main/java/org/springframework/scripting/support/ScriptFactoryPostProcessor.java b/spring-context/src/main/java/org/springframework/scripting/support/ScriptFactoryPostProcessor.java index d655e266ff..034b84c8be 100644 --- a/spring-context/src/main/java/org/springframework/scripting/support/ScriptFactoryPostProcessor.java +++ b/spring-context/src/main/java/org/springframework/scripting/support/ScriptFactoryPostProcessor.java @@ -53,6 +53,7 @@ import org.springframework.core.Conventions; import org.springframework.core.Ordered; import org.springframework.core.io.DefaultResourceLoader; import org.springframework.core.io.ResourceLoader; +import org.springframework.lang.Nullable; import org.springframework.scripting.ScriptFactory; import org.springframework.scripting.ScriptSource; import org.springframework.util.ClassUtils; @@ -557,7 +558,7 @@ public class ScriptFactoryPostProcessor extends InstantiationAwareBeanPostProces * @return the generated proxy * @see RefreshableScriptTargetSource */ - protected Object createRefreshableProxy(TargetSource ts, Class[] interfaces, boolean proxyTargetClass) { + protected Object createRefreshableProxy(TargetSource ts, @Nullable Class[] interfaces, boolean proxyTargetClass) { ProxyFactory proxyFactory = new ProxyFactory(); proxyFactory.setTargetSource(ts); ClassLoader classLoader = this.beanClassLoader; diff --git a/spring-context/src/main/java/org/springframework/scripting/support/StaticScriptSource.java b/spring-context/src/main/java/org/springframework/scripting/support/StaticScriptSource.java index dbd937a0f0..8e2673da2a 100644 --- a/spring-context/src/main/java/org/springframework/scripting/support/StaticScriptSource.java +++ b/spring-context/src/main/java/org/springframework/scripting/support/StaticScriptSource.java @@ -16,6 +16,7 @@ package org.springframework.scripting.support; +import org.springframework.lang.Nullable; import org.springframework.scripting.ScriptSource; import org.springframework.util.Assert; @@ -52,7 +53,7 @@ public class StaticScriptSource implements ScriptSource { * @param className the suggested class name for the script * (may be {@code null}) */ - public StaticScriptSource(String script, String className) { + public StaticScriptSource(String script, @Nullable String className) { setScript(script); this.className = className; } diff --git a/spring-context/src/main/java/org/springframework/scripting/support/package-info.java b/spring-context/src/main/java/org/springframework/scripting/support/package-info.java index 2c640d727f..6fee64c963 100644 --- a/spring-context/src/main/java/org/springframework/scripting/support/package-info.java +++ b/spring-context/src/main/java/org/springframework/scripting/support/package-info.java @@ -3,4 +3,7 @@ * Provides a ScriptFactoryPostProcessor for turning ScriptFactory * definitions into scripted objects. */ +@NonNullApi package org.springframework.scripting.support; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context/src/main/java/org/springframework/stereotype/package-info.java b/spring-context/src/main/java/org/springframework/stereotype/package-info.java index 5bc2ecf287..8754a26814 100644 --- a/spring-context/src/main/java/org/springframework/stereotype/package-info.java +++ b/spring-context/src/main/java/org/springframework/stereotype/package-info.java @@ -4,4 +4,7 @@ * *

Intended for use by tools and aspects (making an ideal target for pointcuts). */ +@NonNullApi package org.springframework.stereotype; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context/src/main/java/org/springframework/ui/ConcurrentModel.java b/spring-context/src/main/java/org/springframework/ui/ConcurrentModel.java index 553120af44..d564b396f8 100644 --- a/spring-context/src/main/java/org/springframework/ui/ConcurrentModel.java +++ b/spring-context/src/main/java/org/springframework/ui/ConcurrentModel.java @@ -21,6 +21,7 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import org.springframework.core.Conventions; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -69,7 +70,7 @@ public class ConcurrentModel extends ConcurrentHashMap implement * @param attributeName the name of the model attribute (never {@code null}) * @param attributeValue the model attribute value (can be {@code null}) */ - public ConcurrentModel addAttribute(String attributeName, Object attributeValue) { + public ConcurrentModel addAttribute(String attributeName, @Nullable Object attributeValue) { Assert.notNull(attributeName, "Model attribute name must not be null"); put(attributeName, attributeValue); return this; diff --git a/spring-context/src/main/java/org/springframework/ui/Model.java b/spring-context/src/main/java/org/springframework/ui/Model.java index 4a51e9182c..2be7496b13 100644 --- a/spring-context/src/main/java/org/springframework/ui/Model.java +++ b/spring-context/src/main/java/org/springframework/ui/Model.java @@ -19,6 +19,8 @@ package org.springframework.ui; import java.util.Collection; import java.util.Map; +import org.springframework.lang.Nullable; + /** * Java-5-specific interface that defines a holder for model attributes. * Primarily designed for adding attributes to the model. @@ -34,7 +36,7 @@ public interface Model { * @param attributeName the name of the model attribute (never {@code null}) * @param attributeValue the model attribute value (can be {@code null}) */ - Model addAttribute(String attributeName, Object attributeValue); + Model addAttribute(String attributeName, @Nullable Object attributeValue); /** * Add the supplied attribute to this {@code Map} using a @@ -45,7 +47,7 @@ public interface Model { * than for empty collections as is already done by JSTL tags. * @param attributeValue the model attribute value (never {@code null}) */ - Model addAttribute(Object attributeValue); + Model addAttribute(@Nullable Object attributeValue); /** * Copy all attributes in the supplied {@code Collection} into this diff --git a/spring-context/src/main/java/org/springframework/ui/ModelMap.java b/spring-context/src/main/java/org/springframework/ui/ModelMap.java index dad6b113b6..6b263795fc 100644 --- a/spring-context/src/main/java/org/springframework/ui/ModelMap.java +++ b/spring-context/src/main/java/org/springframework/ui/ModelMap.java @@ -21,6 +21,7 @@ import java.util.LinkedHashMap; import java.util.Map; import org.springframework.core.Conventions; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -70,7 +71,7 @@ public class ModelMap extends LinkedHashMap { * @param attributeName the name of the model attribute (never {@code null}) * @param attributeValue the model attribute value (can be {@code null}) */ - public ModelMap addAttribute(String attributeName, Object attributeValue) { + public ModelMap addAttribute(String attributeName, @Nullable Object attributeValue) { Assert.notNull(attributeName, "Model attribute name must not be null"); put(attributeName, attributeValue); return this; diff --git a/spring-context/src/main/java/org/springframework/ui/context/HierarchicalThemeSource.java b/spring-context/src/main/java/org/springframework/ui/context/HierarchicalThemeSource.java index e20db315c9..b97568d2b5 100644 --- a/spring-context/src/main/java/org/springframework/ui/context/HierarchicalThemeSource.java +++ b/spring-context/src/main/java/org/springframework/ui/context/HierarchicalThemeSource.java @@ -16,6 +16,8 @@ package org.springframework.ui.context; +import org.springframework.lang.Nullable; + /** * Sub-interface of ThemeSource to be implemented by objects that * can resolve theme messages hierarchically. @@ -32,11 +34,12 @@ public interface HierarchicalThemeSource extends ThemeSource { * resolve messages that this object can't resolve. * May be {@code null}, in which case no further resolution is possible. */ - void setParentThemeSource(ThemeSource parent); + void setParentThemeSource(@Nullable ThemeSource parent); /** * Return the parent of this ThemeSource, or {@code null} if none. */ + @Nullable ThemeSource getParentThemeSource(); } diff --git a/spring-context/src/main/java/org/springframework/ui/context/ThemeSource.java b/spring-context/src/main/java/org/springframework/ui/context/ThemeSource.java index 85c676aa06..43ab228d0b 100644 --- a/spring-context/src/main/java/org/springframework/ui/context/ThemeSource.java +++ b/spring-context/src/main/java/org/springframework/ui/context/ThemeSource.java @@ -16,6 +16,8 @@ package org.springframework.ui.context; +import org.springframework.lang.Nullable; + /** * Interface to be implemented by objects that can resolve {@link Theme Themes}. * This enables parameterization and internationalization of messages @@ -38,6 +40,7 @@ public interface ThemeSource { * return default Themes for other theme names. * @see org.springframework.web.servlet.theme.AbstractThemeResolver#ORIGINAL_DEFAULT_THEME_NAME */ + @Nullable Theme getTheme(String themeName); } diff --git a/spring-context/src/main/java/org/springframework/ui/context/package-info.java b/spring-context/src/main/java/org/springframework/ui/context/package-info.java index ffc6e3d705..355eabb4be 100644 --- a/spring-context/src/main/java/org/springframework/ui/context/package-info.java +++ b/spring-context/src/main/java/org/springframework/ui/context/package-info.java @@ -2,4 +2,7 @@ * Contains classes defining the application context subinterface * for UI applications. The theme feature is added here. */ +@NonNullApi package org.springframework.ui.context; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context/src/main/java/org/springframework/ui/context/support/package-info.java b/spring-context/src/main/java/org/springframework/ui/context/support/package-info.java index f18e77c605..59d7fb291d 100644 --- a/spring-context/src/main/java/org/springframework/ui/context/support/package-info.java +++ b/spring-context/src/main/java/org/springframework/ui/context/support/package-info.java @@ -2,4 +2,7 @@ * Classes supporting the org.springframework.ui.context package. * Provides support classes for specialized UI contexts, e.g. for web UIs. */ +@NonNullApi package org.springframework.ui.context.support; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context/src/main/java/org/springframework/ui/package-info.java b/spring-context/src/main/java/org/springframework/ui/package-info.java index 77380dc8f3..a513de6938 100644 --- a/spring-context/src/main/java/org/springframework/ui/package-info.java +++ b/spring-context/src/main/java/org/springframework/ui/package-info.java @@ -2,4 +2,7 @@ * Generic support for UI layer concepts. * Provides a generic ModelMap for model holding. */ +@NonNullApi package org.springframework.ui; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context/src/main/java/org/springframework/validation/AbstractPropertyBindingResult.java b/spring-context/src/main/java/org/springframework/validation/AbstractPropertyBindingResult.java index 7a3ffc4ac9..e87b0df468 100644 --- a/spring-context/src/main/java/org/springframework/validation/AbstractPropertyBindingResult.java +++ b/spring-context/src/main/java/org/springframework/validation/AbstractPropertyBindingResult.java @@ -25,6 +25,7 @@ import org.springframework.beans.PropertyEditorRegistry; import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.TypeDescriptor; import org.springframework.core.convert.support.ConvertingPropertyEditorAdapter; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -133,6 +134,7 @@ public abstract class AbstractPropertyBindingResult extends AbstractBindingResul * @param fixedField the fully qualified field name * @return the custom PropertyEditor, or {@code null} */ + @Nullable protected PropertyEditor getCustomEditor(String fixedField) { Class targetType = getPropertyAccessor().getPropertyType(fixedField); PropertyEditor editor = getPropertyAccessor().findCustomEditor(targetType, fixedField); diff --git a/spring-context/src/main/java/org/springframework/validation/BindingResult.java b/spring-context/src/main/java/org/springframework/validation/BindingResult.java index 32c93215cb..26e68081ee 100644 --- a/spring-context/src/main/java/org/springframework/validation/BindingResult.java +++ b/spring-context/src/main/java/org/springframework/validation/BindingResult.java @@ -20,6 +20,7 @@ import java.beans.PropertyEditor; import java.util.Map; import org.springframework.beans.PropertyEditorRegistry; +import org.springframework.lang.Nullable; /** * General interface that represents binding results. Extends the @@ -83,6 +84,7 @@ public interface BindingResult extends Errors { * @return the current value of the field in its raw form, * or {@code null} if not known */ + @Nullable Object getRawFieldValue(String field); /** @@ -93,13 +95,15 @@ public interface BindingResult extends Errors { * is given but should be specified in any case for consistency checking) * @return the registered editor, or {@code null} if none */ - PropertyEditor findEditor(String field, Class valueType); + @Nullable + PropertyEditor findEditor(@Nullable String field, @Nullable Class valueType); /** * Return the underlying PropertyEditorRegistry. * @return the PropertyEditorRegistry, or {@code null} if none * available for this BindingResult */ + @Nullable PropertyEditorRegistry getPropertyEditorRegistry(); /** diff --git a/spring-context/src/main/java/org/springframework/validation/BindingResultUtils.java b/spring-context/src/main/java/org/springframework/validation/BindingResultUtils.java index ae3c035768..28f23ab69f 100644 --- a/spring-context/src/main/java/org/springframework/validation/BindingResultUtils.java +++ b/spring-context/src/main/java/org/springframework/validation/BindingResultUtils.java @@ -18,6 +18,7 @@ package org.springframework.validation; import java.util.Map; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -36,6 +37,7 @@ public abstract class BindingResultUtils { * @return the BindingResult, or {@code null} if none found * @throws IllegalStateException if the attribute found is not of type BindingResult */ + @Nullable public static BindingResult getBindingResult(Map model, String name) { Assert.notNull(model, "Model map must not be null"); Assert.notNull(name, "Name must not be null"); diff --git a/spring-context/src/main/java/org/springframework/validation/DataBinder.java b/spring-context/src/main/java/org/springframework/validation/DataBinder.java index 7538ece1da..b5199d314e 100644 --- a/spring-context/src/main/java/org/springframework/validation/DataBinder.java +++ b/spring-context/src/main/java/org/springframework/validation/DataBinder.java @@ -25,6 +25,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import javax.validation.constraints.Null; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -43,6 +45,7 @@ import org.springframework.core.MethodParameter; import org.springframework.core.convert.ConversionService; import org.springframework.format.Formatter; import org.springframework.format.support.FormatterPropertyEditorAdapter; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; import org.springframework.util.PatternMatchUtils; @@ -159,7 +162,7 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter { * if the binder is just used to convert a plain parameter value) * @see #DEFAULT_OBJECT_NAME */ - public DataBinder(Object target) { + public DataBinder(@Nullable Object target) { this(target, DEFAULT_OBJECT_NAME); } @@ -169,7 +172,7 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter { * if the binder is just used to convert a plain parameter value) * @param objectName the name of the target object */ - public DataBinder(Object target, String objectName) { + public DataBinder(@Nullable Object target, String objectName) { this.target = ObjectUtils.unwrapOptional(target); this.objectName = objectName; } @@ -557,6 +560,7 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter { /** * Return the primary Validator to apply after each binding step, if any. */ + @Nullable public Validator getValidator() { return (this.validators.size() > 0 ? this.validators.get(0) : null); } @@ -588,6 +592,7 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter { /** * Return the associated ConversionService, if any. */ + @Nullable public ConversionService getConversionService() { return this.conversionService; } diff --git a/spring-context/src/main/java/org/springframework/validation/Errors.java b/spring-context/src/main/java/org/springframework/validation/Errors.java index bea2a7061b..42c7094e2a 100644 --- a/spring-context/src/main/java/org/springframework/validation/Errors.java +++ b/spring-context/src/main/java/org/springframework/validation/Errors.java @@ -19,6 +19,7 @@ package org.springframework.validation; import java.util.List; import org.springframework.beans.PropertyAccessor; +import org.springframework.lang.Nullable; /** * Stores and exposes information about data-binding and validation @@ -66,13 +67,14 @@ public interface Errors { * e.g. "address" (defaults to "", {@code null} is also acceptable). * Can end with a dot: both "address" and "address." are valid. */ - void setNestedPath(String nestedPath); + void setNestedPath(@Nullable String nestedPath); /** * Return the current nested path of this {@link Errors} object. *

Returns a nested path with a dot, i.e. "address.", for easy * building of concatenated paths. Default is an empty String. */ + @Nullable String getNestedPath(); /** @@ -119,7 +121,7 @@ public interface Errors { * (can be {@code null}) * @param defaultMessage fallback default message */ - void reject(String errorCode, Object[] errorArgs, String defaultMessage); + void reject(String errorCode, @Nullable Object[] errorArgs, String defaultMessage); /** * Register a field error for the specified field of the current object @@ -133,7 +135,7 @@ public interface Errors { * @param errorCode error code, interpretable as a message key * @see #getNestedPath() */ - void rejectValue(String field, String errorCode); + void rejectValue(@Nullable String field, String errorCode); /** * Register a field error for the specified field of the current object @@ -148,7 +150,7 @@ public interface Errors { * @param defaultMessage fallback default message * @see #getNestedPath() */ - void rejectValue(String field, String errorCode, String defaultMessage); + void rejectValue(@Nullable String field, String errorCode, String defaultMessage); /** * Register a field error for the specified field of the current object @@ -165,7 +167,7 @@ public interface Errors { * @param defaultMessage fallback default message * @see #getNestedPath() */ - void rejectValue(String field, String errorCode, Object[] errorArgs, String defaultMessage); + void rejectValue(@Nullable String field, String errorCode, @Nullable Object[] errorArgs, String defaultMessage); /** * Add all errors from the given {@code Errors} instance to this @@ -220,6 +222,7 @@ public interface Errors { * Get the first global error, if any. * @return the global error, or {@code null} */ + @Nullable ObjectError getGlobalError(); /** @@ -246,6 +249,7 @@ public interface Errors { * Get the first error associated with a field, if any. * @return the field-specific error, or {@code null} */ + @Nullable FieldError getFieldError(); /** @@ -276,6 +280,7 @@ public interface Errors { * @param field the field name * @return the field-specific error, or {@code null} */ + @Nullable FieldError getFieldError(String field); /** @@ -296,6 +301,7 @@ public interface Errors { * @param field the field name * @return the type of the field, or {@code null} if not determinable */ - Class getFieldType(String field); + @Nullable + Class getFieldType(@Nullable String field); } diff --git a/spring-context/src/main/java/org/springframework/validation/MessageCodesResolver.java b/spring-context/src/main/java/org/springframework/validation/MessageCodesResolver.java index d86acd476b..14dd97c752 100644 --- a/spring-context/src/main/java/org/springframework/validation/MessageCodesResolver.java +++ b/spring-context/src/main/java/org/springframework/validation/MessageCodesResolver.java @@ -16,6 +16,8 @@ package org.springframework.validation; +import org.springframework.lang.Nullable; + /** * Strategy interface for building message codes from validation error codes. * Used by DataBinder to build the codes list for ObjectErrors and FieldErrors. @@ -50,6 +52,6 @@ public interface MessageCodesResolver { * @param fieldType the field type (may be {@code null} if not determinable) * @return the message codes to use */ - String[] resolveMessageCodes(String errorCode, String objectName, String field, Class fieldType); + String[] resolveMessageCodes(String errorCode, String objectName, String field, @Nullable Class fieldType); } diff --git a/spring-context/src/main/java/org/springframework/validation/SmartValidator.java b/spring-context/src/main/java/org/springframework/validation/SmartValidator.java index 772849e3ec..16f7c7580e 100644 --- a/spring-context/src/main/java/org/springframework/validation/SmartValidator.java +++ b/spring-context/src/main/java/org/springframework/validation/SmartValidator.java @@ -16,6 +16,8 @@ package org.springframework.validation; +import org.springframework.lang.Nullable; + /** * Extended variant of the {@link Validator} interface, adding support for * validation 'hints'. @@ -42,6 +44,6 @@ public interface SmartValidator extends Validator { * @param validationHints one or more hint objects to be passed to the validation engine * @see ValidationUtils */ - void validate(Object target, Errors errors, Object... validationHints); + void validate(@Nullable Object target, Errors errors, Object... validationHints); } diff --git a/spring-context/src/main/java/org/springframework/validation/ValidationUtils.java b/spring-context/src/main/java/org/springframework/validation/ValidationUtils.java index 973078c59d..ebd1084ffa 100644 --- a/spring-context/src/main/java/org/springframework/validation/ValidationUtils.java +++ b/spring-context/src/main/java/org/springframework/validation/ValidationUtils.java @@ -19,6 +19,7 @@ package org.springframework.validation; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; @@ -139,7 +140,7 @@ public abstract class ValidationUtils { * @param errorArgs the error arguments, for argument binding via MessageFormat * (can be {@code null}) */ - public static void rejectIfEmpty(Errors errors, String field, String errorCode, Object[] errorArgs) { + public static void rejectIfEmpty(Errors errors, String field, @Nullable String errorCode, Object[] errorArgs) { rejectIfEmpty(errors, field, errorCode, errorArgs, null); } @@ -159,7 +160,7 @@ public abstract class ValidationUtils { * @param defaultMessage fallback default message */ public static void rejectIfEmpty( - Errors errors, String field, String errorCode, Object[] errorArgs, String defaultMessage) { + Errors errors, String field, String errorCode, @Nullable Object[] errorArgs, String defaultMessage) { Assert.notNull(errors, "Errors object must not be null"); Object value = errors.getFieldValue(field); @@ -218,7 +219,7 @@ public abstract class ValidationUtils { * (can be {@code null}) */ public static void rejectIfEmptyOrWhitespace( - Errors errors, String field, String errorCode, Object[] errorArgs) { + Errors errors, String field, String errorCode, @Nullable Object[] errorArgs) { rejectIfEmptyOrWhitespace(errors, field, errorCode, errorArgs, null); } @@ -239,7 +240,7 @@ public abstract class ValidationUtils { * @param defaultMessage fallback default message */ public static void rejectIfEmptyOrWhitespace( - Errors errors, String field, String errorCode, Object[] errorArgs, String defaultMessage) { + Errors errors, String field, String errorCode, @Nullable Object[] errorArgs, String defaultMessage) { Assert.notNull(errors, "Errors object must not be null"); Object value = errors.getFieldValue(field); diff --git a/spring-context/src/main/java/org/springframework/validation/Validator.java b/spring-context/src/main/java/org/springframework/validation/Validator.java index 0c4d069f03..d5511c602b 100644 --- a/spring-context/src/main/java/org/springframework/validation/Validator.java +++ b/spring-context/src/main/java/org/springframework/validation/Validator.java @@ -16,6 +16,8 @@ package org.springframework.validation; +import org.springframework.lang.Nullable; + /** * A validator for application-specific objects. * @@ -89,6 +91,6 @@ public interface Validator { * @param errors contextual state about the validation process (never {@code null}) * @see ValidationUtils */ - void validate(Object target, Errors errors); + void validate(@Nullable Object target, Errors errors); } diff --git a/spring-context/src/main/java/org/springframework/validation/annotation/package-info.java b/spring-context/src/main/java/org/springframework/validation/annotation/package-info.java index 17f378cb16..8e50d9326e 100644 --- a/spring-context/src/main/java/org/springframework/validation/annotation/package-info.java +++ b/spring-context/src/main/java/org/springframework/validation/annotation/package-info.java @@ -5,4 +5,7 @@ *

Provides an extended variant of JSR-303's {@code @Valid}, * supporting the specification of validation groups. */ +@NonNullApi package org.springframework.validation.annotation; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context/src/main/java/org/springframework/validation/beanvalidation/package-info.java b/spring-context/src/main/java/org/springframework/validation/beanvalidation/package-info.java index a8bea39a03..2f76fd1ba6 100644 --- a/spring-context/src/main/java/org/springframework/validation/beanvalidation/package-info.java +++ b/spring-context/src/main/java/org/springframework/validation/beanvalidation/package-info.java @@ -8,4 +8,7 @@ * which defines a shared ValidatorFactory/Validator setup for availability * to other Spring components. */ +@NonNullApi package org.springframework.validation.beanvalidation; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context/src/main/java/org/springframework/validation/package-info.java b/spring-context/src/main/java/org/springframework/validation/package-info.java index ce6b2dd243..04d9aea2fe 100644 --- a/spring-context/src/main/java/org/springframework/validation/package-info.java +++ b/spring-context/src/main/java/org/springframework/validation/package-info.java @@ -2,4 +2,7 @@ * Provides data binding and validation functionality, * for usage in business and/or UI layers. */ +@NonNullApi package org.springframework.validation; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-context/src/main/java/org/springframework/validation/support/package-info.java b/spring-context/src/main/java/org/springframework/validation/support/package-info.java index 9482069695..595a80b9aa 100644 --- a/spring-context/src/main/java/org/springframework/validation/support/package-info.java +++ b/spring-context/src/main/java/org/springframework/validation/support/package-info.java @@ -1,4 +1,7 @@ /** * Support classes for handling validation results. */ +@NonNullApi package org.springframework.validation.support; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-core/src/main/java/org/springframework/core/AttributeAccessor.java b/spring-core/src/main/java/org/springframework/core/AttributeAccessor.java index 27130bce2b..9d407f708f 100644 --- a/spring-core/src/main/java/org/springframework/core/AttributeAccessor.java +++ b/spring-core/src/main/java/org/springframework/core/AttributeAccessor.java @@ -16,6 +16,8 @@ package org.springframework.core; +import org.springframework.lang.Nullable; + /** * Interface defining a generic contract for attaching and accessing metadata * to/from arbitrary objects. @@ -34,7 +36,7 @@ public interface AttributeAccessor { * @param name the unique attribute key * @param value the attribute value to be attached */ - void setAttribute(String name, Object value); + void setAttribute(String name, @Nullable Object value); /** * Get the value of the attribute identified by {@code name}. @@ -42,6 +44,7 @@ public interface AttributeAccessor { * @param name the unique attribute key * @return the current value of the attribute, if any */ + @Nullable Object getAttribute(String name); /** @@ -50,6 +53,7 @@ public interface AttributeAccessor { * @param name the unique attribute key * @return the last value of the attribute, if any */ + @Nullable Object removeAttribute(String name); /** diff --git a/spring-core/src/main/java/org/springframework/core/BridgeMethodResolver.java b/spring-core/src/main/java/org/springframework/core/BridgeMethodResolver.java index 034f13aa31..b76fb6373f 100644 --- a/spring-core/src/main/java/org/springframework/core/BridgeMethodResolver.java +++ b/spring-core/src/main/java/org/springframework/core/BridgeMethodResolver.java @@ -22,6 +22,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.util.ReflectionUtils; @@ -102,7 +103,8 @@ public abstract class BridgeMethodResolver { * @param bridgeMethod the bridge method * @return the bridged method, or {@code null} if none found */ - private static Method searchCandidates(List candidateMethods, Method bridgeMethod) { + @Nullable + private static Method searchCandidates(@Nullable List candidateMethods, Method bridgeMethod) { if (candidateMethods.isEmpty()) { return null; } @@ -138,6 +140,7 @@ public abstract class BridgeMethodResolver { * matches that of the supplied bridge method. * @throws IllegalStateException if the generic declaration cannot be found */ + @Nullable private static Method findGenericDeclaration(Method bridgeMethod) { // Search parent types for method that has same signature as bridge. Class superclass = bridgeMethod.getDeclaringClass().getSuperclass(); @@ -196,6 +199,7 @@ public abstract class BridgeMethodResolver { * that of the supplied {@link Method}, then this matching {@link Method} is returned, * otherwise {@code null} is returned. */ + @Nullable private static Method searchForMatch(Class type, Method bridgeMethod) { return ReflectionUtils.findMethod(type, bridgeMethod.getName(), bridgeMethod.getParameterTypes()); } diff --git a/spring-core/src/main/java/org/springframework/core/CollectionFactory.java b/spring-core/src/main/java/org/springframework/core/CollectionFactory.java index b21641761b..bac3121171 100644 --- a/spring-core/src/main/java/org/springframework/core/CollectionFactory.java +++ b/spring-core/src/main/java/org/springframework/core/CollectionFactory.java @@ -36,6 +36,7 @@ import java.util.SortedSet; import java.util.TreeMap; import java.util.TreeSet; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; @@ -115,7 +116,7 @@ public abstract class CollectionFactory { * @see java.util.LinkedHashSet */ @SuppressWarnings({ "unchecked", "cast", "rawtypes" }) - public static Collection createApproximateCollection(Object collection, int capacity) { + public static Collection createApproximateCollection(@Nullable Object collection, int capacity) { if (collection instanceof LinkedList) { return new LinkedList<>(); } @@ -174,7 +175,7 @@ public abstract class CollectionFactory { * the supplied {@code elementType} is not a subtype of {@link Enum} */ @SuppressWarnings({ "unchecked", "cast" }) - public static Collection createCollection(Class collectionType, Class elementType, int capacity) { + public static Collection createCollection(Class collectionType, @Nullable Class elementType, int capacity) { Assert.notNull(collectionType, "Collection type must not be null"); if (collectionType.isInterface()) { if (Set.class == collectionType || Collection.class == collectionType) { @@ -237,7 +238,7 @@ public abstract class CollectionFactory { * @see java.util.LinkedHashMap */ @SuppressWarnings({"unchecked", "rawtypes"}) - public static Map createApproximateMap(Object map, int capacity) { + public static Map createApproximateMap(@Nullable Object map, int capacity) { if (map instanceof EnumMap) { EnumMap enumMap = new EnumMap((EnumMap) map); enumMap.clear(); @@ -290,7 +291,7 @@ public abstract class CollectionFactory { * the supplied {@code keyType} is not a subtype of {@link Enum} */ @SuppressWarnings({"unchecked", "rawtypes"}) - public static Map createMap(Class mapType, Class keyType, int capacity) { + public static Map createMap(Class mapType, @Nullable Class keyType, int capacity) { Assert.notNull(mapType, "Map type must not be null"); if (mapType.isInterface()) { if (Map.class == mapType) { diff --git a/spring-core/src/main/java/org/springframework/core/ConfigurableObjectInputStream.java b/spring-core/src/main/java/org/springframework/core/ConfigurableObjectInputStream.java index 70a0a87c88..01b1dd1275 100644 --- a/spring-core/src/main/java/org/springframework/core/ConfigurableObjectInputStream.java +++ b/spring-core/src/main/java/org/springframework/core/ConfigurableObjectInputStream.java @@ -22,6 +22,7 @@ import java.io.NotSerializableException; import java.io.ObjectInputStream; import java.io.ObjectStreamClass; +import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; /** @@ -142,6 +143,7 @@ public class ConfigurableObjectInputStream extends ObjectInputStream { *

The default implementation simply returns {@code null}, indicating * that no specific fallback is available. */ + @Nullable protected ClassLoader getFallbackClassLoader() throws IOException { return null; } diff --git a/spring-core/src/main/java/org/springframework/core/Constants.java b/spring-core/src/main/java/org/springframework/core/Constants.java index 5045d09a52..a3a70f2e7e 100644 --- a/spring-core/src/main/java/org/springframework/core/Constants.java +++ b/spring-core/src/main/java/org/springframework/core/Constants.java @@ -23,6 +23,7 @@ import java.util.Locale; import java.util.Map; import java.util.Set; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ReflectionUtils; @@ -157,7 +158,7 @@ public class Constants { * @param namePrefix prefix of the constant names to search (may be {@code null}) * @return the set of constant names */ - public Set getNames(String namePrefix) { + public Set getNames(@Nullable String namePrefix) { String prefixToUse = (namePrefix != null ? namePrefix.trim().toUpperCase(Locale.ENGLISH) : ""); Set names = new HashSet<>(); for (String code : this.fieldCache.keySet()) { @@ -189,7 +190,7 @@ public class Constants { * @param nameSuffix suffix of the constant names to search (may be {@code null}) * @return the set of constant names */ - public Set getNamesForSuffix(String nameSuffix) { + public Set getNamesForSuffix(@Nullable String nameSuffix) { String suffixToUse = (nameSuffix != null ? nameSuffix.trim().toUpperCase(Locale.ENGLISH) : ""); Set names = new HashSet<>(); for (String code : this.fieldCache.keySet()) { @@ -211,7 +212,7 @@ public class Constants { * @param namePrefix prefix of the constant names to search (may be {@code null}) * @return the set of values */ - public Set getValues(String namePrefix) { + public Set getValues(@Nullable String namePrefix) { String prefixToUse = (namePrefix != null ? namePrefix.trim().toUpperCase(Locale.ENGLISH) : ""); Set values = new HashSet<>(); for (String code : this.fieldCache.keySet()) { @@ -243,7 +244,7 @@ public class Constants { * @param nameSuffix suffix of the constant names to search (may be {@code null}) * @return the set of values */ - public Set getValuesForSuffix(String nameSuffix) { + public Set getValuesForSuffix(@Nullable String nameSuffix) { String suffixToUse = (nameSuffix != null ? nameSuffix.trim().toUpperCase(Locale.ENGLISH) : ""); Set values = new HashSet<>(); for (String code : this.fieldCache.keySet()) { @@ -263,7 +264,7 @@ public class Constants { * @return the name of the constant field * @throws ConstantException if the value wasn't found */ - public String toCode(Object value, String namePrefix) throws ConstantException { + public String toCode(Object value, @Nullable String namePrefix) throws ConstantException { String prefixToUse = (namePrefix != null ? namePrefix.trim().toUpperCase(Locale.ENGLISH) : ""); for (Map.Entry entry : this.fieldCache.entrySet()) { if (entry.getKey().startsWith(prefixToUse) && entry.getValue().equals(value)) { @@ -294,7 +295,7 @@ public class Constants { * @return the name of the constant field * @throws ConstantException if the value wasn't found */ - public String toCodeForSuffix(Object value, String nameSuffix) throws ConstantException { + public String toCodeForSuffix(Object value, @Nullable String nameSuffix) throws ConstantException { String suffixToUse = (nameSuffix != null ? nameSuffix.trim().toUpperCase(Locale.ENGLISH) : ""); for (Map.Entry entry : this.fieldCache.entrySet()) { if (entry.getKey().endsWith(suffixToUse) && entry.getValue().equals(value)) { diff --git a/spring-core/src/main/java/org/springframework/core/Conventions.java b/spring-core/src/main/java/org/springframework/core/Conventions.java index 1fbeeae686..95bbef49e6 100644 --- a/spring-core/src/main/java/org/springframework/core/Conventions.java +++ b/spring-core/src/main/java/org/springframework/core/Conventions.java @@ -27,6 +27,7 @@ import java.util.HashSet; import java.util.Iterator; import java.util.Set; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; @@ -171,7 +172,7 @@ public abstract class Conventions { * @param value the return value (may be {@code null} if not available) * @return the generated variable name */ - public static String getVariableNameForReturnType(Method method, Object value) { + public static String getVariableNameForReturnType(Method method, @Nullable Object value) { return getVariableNameForReturnType(method, method.getReturnType(), value); } @@ -191,7 +192,7 @@ public abstract class Conventions { * @param value the return value (may be {@code null} if not available) * @return the generated variable name */ - public static String getVariableNameForReturnType(Method method, Class resolvedType, Object value) { + public static String getVariableNameForReturnType(Method method, Class resolvedType, @Nullable Object value) { Assert.notNull(method, "Method must not be null"); if (Object.class == resolvedType) { diff --git a/spring-core/src/main/java/org/springframework/core/GenericTypeResolver.java b/spring-core/src/main/java/org/springframework/core/GenericTypeResolver.java index eb00d48d0f..ad97bc5940 100644 --- a/spring-core/src/main/java/org/springframework/core/GenericTypeResolver.java +++ b/spring-core/src/main/java/org/springframework/core/GenericTypeResolver.java @@ -25,6 +25,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.Map; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ConcurrentReferenceHashMap; @@ -83,6 +84,7 @@ public abstract class GenericTypeResolver { * @return the resolved parameter type of the method return type, or {@code null} * if not resolvable or if the single argument is of type {@link WildcardType}. */ + @Nullable public static Class resolveReturnTypeArgument(Method method, Class genericIfc) { Assert.notNull(method, "method must not be null"); ResolvableType resolvableType = ResolvableType.forMethodReturnType(method).as(genericIfc); @@ -100,6 +102,7 @@ public abstract class GenericTypeResolver { * @param genericIfc the generic interface or superclass to resolve the type argument from * @return the resolved type of the argument, or {@code null} if not resolvable */ + @Nullable public static Class resolveTypeArgument(Class clazz, Class genericIfc) { ResolvableType resolvableType = ResolvableType.forClass(clazz).as(genericIfc); if (!resolvableType.hasGenerics()) { @@ -125,6 +128,7 @@ public abstract class GenericTypeResolver { * @return the resolved type of each argument, with the array size matching the * number of actual type arguments, or {@code null} if not resolvable */ + @Nullable public static Class[] resolveTypeArguments(Class clazz, Class genericIfc) { ResolvableType type = ResolvableType.forClass(clazz).as(genericIfc); if (!type.hasGenerics() || type.isEntirelyUnresolvable()) { @@ -142,6 +146,7 @@ public abstract class GenericTypeResolver { * @return the resolved type (possibly the given generic type as-is) * @since 5.0 */ + @Nullable public static Type resolveType(Type genericType, Class contextClass) { if (contextClass != null) { if (genericType instanceof TypeVariable) { diff --git a/spring-core/src/main/java/org/springframework/core/MethodClassKey.java b/spring-core/src/main/java/org/springframework/core/MethodClassKey.java index b837fc6486..4435612880 100644 --- a/spring-core/src/main/java/org/springframework/core/MethodClassKey.java +++ b/spring-core/src/main/java/org/springframework/core/MethodClassKey.java @@ -18,6 +18,7 @@ package org.springframework.core; import java.lang.reflect.Method; +import org.springframework.lang.Nullable; import org.springframework.util.ObjectUtils; /** @@ -41,7 +42,7 @@ public final class MethodClassKey implements Comparable { * @param targetClass the target class that the method will be invoked * on (may be {@code null} if identical to the declaring class) */ - public MethodClassKey(Method method, Class targetClass) { + public MethodClassKey(Method method, @Nullable Class targetClass) { this.method = method; this.targetClass = targetClass; } diff --git a/spring-core/src/main/java/org/springframework/core/MethodIntrospector.java b/spring-core/src/main/java/org/springframework/core/MethodIntrospector.java index 0f8e396556..8e3439ca7c 100644 --- a/spring-core/src/main/java/org/springframework/core/MethodIntrospector.java +++ b/spring-core/src/main/java/org/springframework/core/MethodIntrospector.java @@ -24,6 +24,7 @@ import java.util.LinkedHashSet; import java.util.Map; import java.util.Set; +import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.util.ReflectionUtils; @@ -51,7 +52,7 @@ public abstract class MethodIntrospector { * @return the selected methods associated with their metadata (in the order of retrieval), * or an empty map in case of no match */ - public static Map selectMethods(Class targetType, final MetadataLookup metadataLookup) { + public static Map selectMethods(Class targetType, @Nullable final MetadataLookup metadataLookup) { final Map methodMap = new LinkedHashMap<>(); Set> handlerTypes = new LinkedHashSet<>(); Class specificHandlerType = null; @@ -155,6 +156,7 @@ public abstract class MethodIntrospector { * @return non-null metadata to be associated with a method if there is a match, * or {@code null} for no match */ + @Nullable T inspect(Method method); } diff --git a/spring-core/src/main/java/org/springframework/core/MethodParameter.java b/spring-core/src/main/java/org/springframework/core/MethodParameter.java index 14d18544f1..0f3481a502 100644 --- a/spring-core/src/main/java/org/springframework/core/MethodParameter.java +++ b/spring-core/src/main/java/org/springframework/core/MethodParameter.java @@ -36,6 +36,7 @@ import kotlin.reflect.KFunction; import kotlin.reflect.KParameter; import kotlin.reflect.jvm.ReflectJvmMapping; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; @@ -171,6 +172,7 @@ public class MethodParameter { *

Note: Either Method or Constructor is available. * @return the Method, or {@code null} if none */ + @Nullable public Method getMethod() { return this.method; } @@ -180,6 +182,7 @@ public class MethodParameter { *

Note: Either Method or Constructor is available. * @return the Constructor, or {@code null} if none */ + @Nullable public Constructor getConstructor() { return this.constructor; } @@ -279,6 +282,7 @@ public class MethodParameter { * if none specified (indicating the default type index) * @see #getNestingLevel() */ + @Nullable public Integer getTypeIndexForCurrentLevel() { return getTypeIndexForLevel(this.nestingLevel); } @@ -289,6 +293,7 @@ public class MethodParameter { * @return the corresponding type index, or {@code null} * if none specified (indicating the default type index) */ + @Nullable public Integer getTypeIndexForLevel(int nestingLevel) { return getTypeIndexesPerLevel().get(nestingLevel); } @@ -482,6 +487,7 @@ public class MethodParameter { * @param annotationType the annotation type to look for * @return the annotation object, or {@code null} if not found */ + @Nullable public A getMethodAnnotation(Class annotationType) { return adaptAnnotation(getAnnotatedElement().getAnnotation(annotationType)); } @@ -528,6 +534,7 @@ public class MethodParameter { * @return the annotation object, or {@code null} if not found */ @SuppressWarnings("unchecked") + @Nullable public A getParameterAnnotation(Class annotationType) { Annotation[] anns = getParameterAnnotations(); for (Annotation ann : anns) { @@ -564,6 +571,7 @@ public class MethodParameter { * {@link #initParameterNameDiscovery ParameterNameDiscoverer} * has been set to begin with) */ + @Nullable public String getParameterName() { ParameterNameDiscoverer discoverer = this.parameterNameDiscoverer; if (discoverer != null) { diff --git a/spring-core/src/main/java/org/springframework/core/NestedCheckedException.java b/spring-core/src/main/java/org/springframework/core/NestedCheckedException.java index 0cb2920dce..8b786f180a 100644 --- a/spring-core/src/main/java/org/springframework/core/NestedCheckedException.java +++ b/spring-core/src/main/java/org/springframework/core/NestedCheckedException.java @@ -16,6 +16,8 @@ package org.springframework.core; +import org.springframework.lang.Nullable; + /** * Handy class for wrapping checked {@code Exceptions} with a root cause. * @@ -79,6 +81,7 @@ public abstract class NestedCheckedException extends Exception { * Retrieve the innermost cause of this exception, if any. * @return the innermost exception, or {@code null} if none */ + @Nullable public Throwable getRootCause() { return NestedExceptionUtils.getRootCause(this); } diff --git a/spring-core/src/main/java/org/springframework/core/NestedExceptionUtils.java b/spring-core/src/main/java/org/springframework/core/NestedExceptionUtils.java index e7c11aed75..7fd024601b 100644 --- a/spring-core/src/main/java/org/springframework/core/NestedExceptionUtils.java +++ b/spring-core/src/main/java/org/springframework/core/NestedExceptionUtils.java @@ -16,6 +16,8 @@ package org.springframework.core; +import org.springframework.lang.Nullable; + /** * Helper class for implementing exception classes which are capable of * holding nested exceptions. Necessary because we can't share a base @@ -56,6 +58,7 @@ public abstract class NestedExceptionUtils { * @return the innermost exception, or {@code null} if none * @since 4.3.9 */ + @Nullable public static Throwable getRootCause(Throwable original) { if (original == null) { return null; diff --git a/spring-core/src/main/java/org/springframework/core/NestedRuntimeException.java b/spring-core/src/main/java/org/springframework/core/NestedRuntimeException.java index 6e8843f0f8..5cb6832c2c 100644 --- a/spring-core/src/main/java/org/springframework/core/NestedRuntimeException.java +++ b/spring-core/src/main/java/org/springframework/core/NestedRuntimeException.java @@ -16,6 +16,8 @@ package org.springframework.core; +import org.springframework.lang.Nullable; + /** * Handy class for wrapping runtime {@code Exceptions} with a root cause. * @@ -80,6 +82,7 @@ public abstract class NestedRuntimeException extends RuntimeException { * @return the innermost exception, or {@code null} if none * @since 2.0 */ + @Nullable public Throwable getRootCause() { return NestedExceptionUtils.getRootCause(this); } diff --git a/spring-core/src/main/java/org/springframework/core/OrderComparator.java b/spring-core/src/main/java/org/springframework/core/OrderComparator.java index 39e27ac56c..0f8fa5e54d 100644 --- a/spring-core/src/main/java/org/springframework/core/OrderComparator.java +++ b/spring-core/src/main/java/org/springframework/core/OrderComparator.java @@ -21,6 +21,7 @@ import java.util.Collections; import java.util.Comparator; import java.util.List; +import org.springframework.lang.Nullable; import org.springframework.util.ObjectUtils; /** @@ -135,6 +136,7 @@ public class OrderComparator implements Comparator { * @param obj the object to check * @return the order value, or {@code null} if none found */ + @Nullable protected Integer findOrder(Object obj) { return (obj instanceof Ordered ? ((Ordered) obj).getOrder() : null); } @@ -150,6 +152,7 @@ public class OrderComparator implements Comparator { * @return the priority value, or {@code null} if none * @since 4.1 */ + @Nullable public Integer getPriority(Object obj) { return null; } @@ -215,6 +218,7 @@ public class OrderComparator implements Comparator { * @param obj the object to find an order source for * @return the order source for that object, or {@code null} if none found */ + @Nullable Object getOrderSource(Object obj); } diff --git a/spring-core/src/main/java/org/springframework/core/OverridingClassLoader.java b/spring-core/src/main/java/org/springframework/core/OverridingClassLoader.java index 5a45cde1f2..f0b0602ee4 100644 --- a/spring-core/src/main/java/org/springframework/core/OverridingClassLoader.java +++ b/spring-core/src/main/java/org/springframework/core/OverridingClassLoader.java @@ -19,6 +19,7 @@ package org.springframework.core; import java.io.IOException; import java.io.InputStream; +import org.springframework.lang.Nullable; import org.springframework.util.FileCopyUtils; /** @@ -113,6 +114,7 @@ public class OverridingClassLoader extends DecoratingClassLoader { * @return the Class object, or {@code null} if no class defined for that name * @throws ClassNotFoundException if the class for the given name couldn't be loaded */ + @Nullable protected Class loadClassForOverriding(String name) throws ClassNotFoundException { Class result = findLoadedClass(name); if (result == null) { @@ -134,6 +136,7 @@ public class OverridingClassLoader extends DecoratingClassLoader { * or {@code null} if no class defined for that name * @throws ClassNotFoundException if the class for the given name couldn't be loaded */ + @Nullable protected byte[] loadBytesForClass(String name) throws ClassNotFoundException { InputStream is = openStreamForClass(name); if (is == null) { diff --git a/spring-core/src/main/java/org/springframework/core/ParameterNameDiscoverer.java b/spring-core/src/main/java/org/springframework/core/ParameterNameDiscoverer.java index 01356c2967..8c551f2140 100644 --- a/spring-core/src/main/java/org/springframework/core/ParameterNameDiscoverer.java +++ b/spring-core/src/main/java/org/springframework/core/ParameterNameDiscoverer.java @@ -19,6 +19,8 @@ package org.springframework.core; import java.lang.reflect.Constructor; import java.lang.reflect.Method; +import org.springframework.lang.Nullable; + /** * Interface to discover parameter names for methods and constructors. * @@ -40,6 +42,7 @@ public interface ParameterNameDiscoverer { * @return an array of parameter names if the names can be resolved, * or {@code null} if they cannot */ + @Nullable String[] getParameterNames(Method method); /** @@ -49,6 +52,7 @@ public interface ParameterNameDiscoverer { * @return an array of parameter names if the names can be resolved, * or {@code null} if they cannot */ + @Nullable String[] getParameterNames(Constructor ctor); } diff --git a/spring-core/src/main/java/org/springframework/core/ReactiveAdapterRegistry.java b/spring-core/src/main/java/org/springframework/core/ReactiveAdapterRegistry.java index 3a22bbcb1e..7954b9dcf2 100644 --- a/spring-core/src/main/java/org/springframework/core/ReactiveAdapterRegistry.java +++ b/spring-core/src/main/java/org/springframework/core/ReactiveAdapterRegistry.java @@ -28,6 +28,7 @@ import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import rx.RxReactiveStreams; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; @@ -120,7 +121,8 @@ public class ReactiveAdapterRegistry { * @param source an instance of the reactive type * (i.e. to adapt from; may be {@code null} if the reactive type is specified) */ - public ReactiveAdapter getAdapter(Class reactiveType, Object source) { + @Nullable + public ReactiveAdapter getAdapter(@Nullable Class reactiveType, Object source) { Object sourceToUse = (source instanceof Optional ? ((Optional) source).orElse(null) : source); Class clazz = (sourceToUse != null ? sourceToUse.getClass() : reactiveType); diff --git a/spring-core/src/main/java/org/springframework/core/ResolvableType.java b/spring-core/src/main/java/org/springframework/core/ResolvableType.java index fc79e4fbcd..1347a3ed80 100644 --- a/spring-core/src/main/java/org/springframework/core/ResolvableType.java +++ b/spring-core/src/main/java/org/springframework/core/ResolvableType.java @@ -34,6 +34,7 @@ import java.util.Map; import org.springframework.core.SerializableTypeWrapper.FieldTypeProvider; import org.springframework.core.SerializableTypeWrapper.MethodParameterTypeProvider; import org.springframework.core.SerializableTypeWrapper.TypeProvider; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.ConcurrentReferenceHashMap; @@ -196,6 +197,7 @@ public class ResolvableType implements Serializable { * Return the underlying Java {@link Class} being managed, if available; * otherwise {@code null}. */ + @Nullable public Class getRawClass() { if (this.type == this.resolved) { return this.resolved; @@ -587,7 +589,7 @@ public class ResolvableType implements Serializable { * level (may be {@code null}) * @return a {@link ResolvableType} for the nested level or {@link #NONE} */ - public ResolvableType getNested(int nestingLevel, Map typeIndexesPerLevel) { + public ResolvableType getNested(int nestingLevel, @Nullable Map typeIndexesPerLevel) { ResolvableType result = this; for (int i = 2; i <= nestingLevel; i++) { if (result.isArray()) { @@ -716,6 +718,7 @@ public class ResolvableType implements Serializable { * @see #getGeneric(int...) * @see #resolve() */ + @Nullable public Class resolveGeneric(int... indexes) { return getGeneric(indexes).resolve(); } @@ -730,6 +733,7 @@ public class ResolvableType implements Serializable { * @see #resolveGeneric(int...) * @see #resolveGenerics() */ + @Nullable public Class resolve() { return resolve(null); } @@ -745,7 +749,7 @@ public class ResolvableType implements Serializable { * @see #resolveGeneric(int...) * @see #resolveGenerics() */ - public Class resolve(Class fallback) { + public Class resolve(@Nullable Class fallback) { return (this.resolved != null ? this.resolved : fallback); } @@ -791,6 +795,7 @@ public class ResolvableType implements Serializable { return NONE; } + @Nullable private Type resolveBounds(Type[] bounds) { if (ObjectUtils.isEmpty(bounds) || Object.class == bounds[0]) { return null; @@ -798,6 +803,7 @@ public class ResolvableType implements Serializable { return bounds[0]; } + @Nullable private ResolvableType resolveVariable(TypeVariable variable) { if (this.type instanceof TypeVariable) { return resolveType().resolveVariable(variable); @@ -873,6 +879,7 @@ public class ResolvableType implements Serializable { /** * Adapts this {@link ResolvableType} to a {@link VariableResolver}. */ + @Nullable VariableResolver asVariableResolver() { if (this == NONE) { return null; @@ -929,7 +936,7 @@ public class ResolvableType implements Serializable { * @see #forClass(Class, Class) * @see #forClassWithGenerics(Class, Class...) */ - public static ResolvableType forClass(Class clazz) { + public static ResolvableType forClass(@Nullable Class clazz) { return new ResolvableType(clazz); } @@ -945,7 +952,7 @@ public class ResolvableType implements Serializable { * @see #forClass(Class) * @see #getRawClass() */ - public static ResolvableType forRawClass(Class clazz) { + public static ResolvableType forRawClass(@Nullable Class clazz) { return new ResolvableType(clazz) { @Override public ResolvableType[] getGenerics() { @@ -1289,7 +1296,7 @@ public class ResolvableType implements Serializable { * @return a {@link ResolvableType} for the specified {@link Type} * @see #forType(Type, ResolvableType) */ - public static ResolvableType forType(Type type) { + public static ResolvableType forType(@Nullable Type type) { return forType(type, null, null); } @@ -1301,7 +1308,7 @@ public class ResolvableType implements Serializable { * @return a {@link ResolvableType} for the specified {@link Type} and owner * @see #forType(Type) */ - public static ResolvableType forType(Type type, ResolvableType owner) { + public static ResolvableType forType(@Nullable Type type, ResolvableType owner) { VariableResolver variableResolver = null; if (owner != null) { variableResolver = owner.asVariableResolver(); @@ -1316,7 +1323,7 @@ public class ResolvableType implements Serializable { * @param variableResolver the variable resolver or {@code null} * @return a {@link ResolvableType} for the specified {@link Type} and {@link VariableResolver} */ - static ResolvableType forType(Type type, VariableResolver variableResolver) { + static ResolvableType forType(@Nullable Type type, @Nullable VariableResolver variableResolver) { return forType(type, null, variableResolver); } @@ -1328,7 +1335,7 @@ public class ResolvableType implements Serializable { * @param variableResolver the variable resolver or {@code null} * @return a {@link ResolvableType} for the specified {@link Type} and {@link VariableResolver} */ - static ResolvableType forType(Type type, TypeProvider typeProvider, VariableResolver variableResolver) { + static ResolvableType forType(@Nullable Type type, @Nullable TypeProvider typeProvider, @Nullable VariableResolver variableResolver) { if (type == null && typeProvider != null) { type = SerializableTypeWrapper.forTypeProvider(typeProvider); } @@ -1380,6 +1387,7 @@ public class ResolvableType implements Serializable { * @param variable the variable to resolve * @return the resolved variable, or {@code null} if not found */ + @Nullable ResolvableType resolveVariable(TypeVariable variable); } @@ -1535,6 +1543,7 @@ public class ResolvableType implements Serializable { * @param type the source type * @return a {@link WildcardBounds} instance or {@code null} */ + @Nullable public static WildcardBounds get(ResolvableType type) { ResolvableType resolveToWildcard = type; while (!(resolveToWildcard.getType() instanceof WildcardType)) { diff --git a/spring-core/src/main/java/org/springframework/core/ResolvableTypeProvider.java b/spring-core/src/main/java/org/springframework/core/ResolvableTypeProvider.java index 1f361fbc5d..948e92f4f4 100644 --- a/spring-core/src/main/java/org/springframework/core/ResolvableTypeProvider.java +++ b/spring-core/src/main/java/org/springframework/core/ResolvableTypeProvider.java @@ -16,6 +16,8 @@ package org.springframework.core; +import org.springframework.lang.Nullable; + /** * Any object can implement this interface to provide its actual {@link ResolvableType}. * @@ -35,6 +37,7 @@ public interface ResolvableTypeProvider { * Return the {@link ResolvableType} describing this instance * (or {@code null} if some sort of default should be applied instead). */ + @Nullable ResolvableType getResolvableType(); } diff --git a/spring-core/src/main/java/org/springframework/core/SerializableTypeWrapper.java b/spring-core/src/main/java/org/springframework/core/SerializableTypeWrapper.java index 8d91564bad..32e3b492c0 100644 --- a/spring-core/src/main/java/org/springframework/core/SerializableTypeWrapper.java +++ b/spring-core/src/main/java/org/springframework/core/SerializableTypeWrapper.java @@ -30,6 +30,7 @@ import java.lang.reflect.Type; import java.lang.reflect.TypeVariable; import java.lang.reflect.WildcardType; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ConcurrentReferenceHashMap; import org.springframework.util.ReflectionUtils; @@ -179,6 +180,7 @@ abstract class SerializableTypeWrapper { * Return the source of the type, or {@code null} if not known. *

The default implementations returns {@code null}. */ + @Nullable default Object getSource() { return null; } diff --git a/spring-core/src/main/java/org/springframework/core/SpringProperties.java b/spring-core/src/main/java/org/springframework/core/SpringProperties.java index f5c3499428..dedeed6ee4 100644 --- a/spring-core/src/main/java/org/springframework/core/SpringProperties.java +++ b/spring-core/src/main/java/org/springframework/core/SpringProperties.java @@ -24,6 +24,8 @@ import java.util.Properties; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.lang.Nullable; + /** * Static holder for local Spring properties, i.e. defined at the Spring library level. * @@ -83,7 +85,7 @@ public abstract class SpringProperties { * @param key the property key * @param value the associated property value, or {@code null} to reset it */ - public static void setProperty(String key, String value) { + public static void setProperty(String key, @Nullable String value) { if (value != null) { localProperties.setProperty(key, value); } @@ -98,6 +100,7 @@ public abstract class SpringProperties { * @param key the property key * @return the associated property value, or {@code null} if none found */ + @Nullable public static String getProperty(String key) { String value = localProperties.getProperty(key); if (value == null) { diff --git a/spring-core/src/main/java/org/springframework/core/SpringVersion.java b/spring-core/src/main/java/org/springframework/core/SpringVersion.java index 38426f1be8..a8c7fcead5 100644 --- a/spring-core/src/main/java/org/springframework/core/SpringVersion.java +++ b/spring-core/src/main/java/org/springframework/core/SpringVersion.java @@ -16,6 +16,8 @@ package org.springframework.core; +import org.springframework.lang.Nullable; + /** * Class that exposes the Spring version. Fetches the * "Implementation-Version" manifest attribute from the jar file. @@ -36,6 +38,7 @@ public class SpringVersion { * or {@code null} if it cannot be determined. * @see Package#getImplementationVersion() */ + @Nullable public static String getVersion() { Package pkg = SpringVersion.class.getPackage(); return (pkg != null ? pkg.getImplementationVersion() : null); diff --git a/spring-core/src/main/java/org/springframework/core/annotation/AbstractAliasAwareAnnotationAttributeExtractor.java b/spring-core/src/main/java/org/springframework/core/annotation/AbstractAliasAwareAnnotationAttributeExtractor.java index 32b8725c2d..64602fa523 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/AbstractAliasAwareAnnotationAttributeExtractor.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/AbstractAliasAwareAnnotationAttributeExtractor.java @@ -21,6 +21,7 @@ import java.lang.reflect.Method; import java.util.List; import java.util.Map; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; @@ -55,7 +56,7 @@ abstract class AbstractAliasAwareAnnotationAttributeExtractor implements Anno * @param source the underlying source of annotation attributes; never {@code null} */ AbstractAliasAwareAnnotationAttributeExtractor( - Class annotationType, Object annotatedElement, S source) { + Class annotationType, @Nullable Object annotatedElement, S source) { Assert.notNull(annotationType, "annotationType must not be null"); Assert.notNull(source, "source must not be null"); diff --git a/spring-core/src/main/java/org/springframework/core/annotation/AnnotatedElementUtils.java b/spring-core/src/main/java/org/springframework/core/annotation/AnnotatedElementUtils.java index 9643760d33..18582f5039 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/AnnotatedElementUtils.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/AnnotatedElementUtils.java @@ -28,6 +28,7 @@ import java.util.Map; import java.util.Set; import org.springframework.core.BridgeMethodResolver; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; @@ -149,6 +150,7 @@ public class AnnotatedElementUtils { * @see #getMetaAnnotationTypes(AnnotatedElement, String) * @see #hasMetaAnnotationTypes */ + @Nullable public static Set getMetaAnnotationTypes(AnnotatedElement element, Class annotationType) { Assert.notNull(element, "AnnotatedElement must not be null"); Assert.notNull(annotationType, "'annotationType' must not be null"); @@ -170,6 +172,7 @@ public class AnnotatedElementUtils { * @see #getMetaAnnotationTypes(AnnotatedElement, Class) * @see #hasMetaAnnotationTypes */ + @Nullable public static Set getMetaAnnotationTypes(AnnotatedElement element, String annotationName) { Assert.notNull(element, "AnnotatedElement must not be null"); Assert.hasLength(annotationName, "'annotationName' must not be null or empty"); @@ -312,6 +315,7 @@ public class AnnotatedElementUtils { * @see #getMergedAnnotation(AnnotatedElement, Class) * @see #findMergedAnnotation(AnnotatedElement, Class) */ + @Nullable public static AnnotationAttributes getMergedAnnotationAttributes( AnnotatedElement element, Class annotationType) { @@ -340,6 +344,7 @@ public class AnnotatedElementUtils { * @see #findMergedAnnotation(AnnotatedElement, Class) * @see #getAllAnnotationAttributes(AnnotatedElement, String) */ + @Nullable public static AnnotationAttributes getMergedAnnotationAttributes(AnnotatedElement element, String annotationName) { return getMergedAnnotationAttributes(element, annotationName, false, false); } @@ -370,6 +375,7 @@ public class AnnotatedElementUtils { * @see #findMergedAnnotationAttributes(AnnotatedElement, String, boolean, boolean) * @see #getAllAnnotationAttributes(AnnotatedElement, String, boolean, boolean) */ + @Nullable public static AnnotationAttributes getMergedAnnotationAttributes(AnnotatedElement element, String annotationName, boolean classValuesAsString, boolean nestedAnnotationsAsMap) { @@ -398,6 +404,7 @@ public class AnnotatedElementUtils { * @see #findMergedAnnotation(AnnotatedElement, Class) * @see AnnotationUtils#synthesizeAnnotation(Map, Class, AnnotatedElement) */ + @Nullable public static A getMergedAnnotation(AnnotatedElement element, Class annotationType) { Assert.notNull(annotationType, "'annotationType' must not be null"); @@ -504,7 +511,7 @@ public class AnnotatedElementUtils { * is not a valid container annotation for the supplied {@code annotationType} */ public static Set getMergedRepeatableAnnotations(AnnotatedElement element, - Class annotationType, Class containerType) { + Class annotationType, @Nullable Class containerType) { Assert.notNull(element, "AnnotatedElement must not be null"); Assert.notNull(annotationType, "'annotationType' must not be null"); @@ -535,6 +542,7 @@ public class AnnotatedElementUtils { * attributes from all annotations found, or {@code null} if not found * @see #getAllAnnotationAttributes(AnnotatedElement, String, boolean, boolean) */ + @Nullable public static MultiValueMap getAllAnnotationAttributes(AnnotatedElement element, String annotationName) { return getAllAnnotationAttributes(element, annotationName, false, false); } @@ -557,6 +565,7 @@ public class AnnotatedElementUtils { * @return a {@link MultiValueMap} keyed by attribute name, containing the annotation * attributes from all annotations found, or {@code null} if not found */ + @Nullable public static MultiValueMap getAllAnnotationAttributes(AnnotatedElement element, String annotationName, final boolean classValuesAsString, final boolean nestedAnnotationsAsMap) { @@ -632,6 +641,7 @@ public class AnnotatedElementUtils { * @see #findMergedAnnotation(AnnotatedElement, Class) * @see #getMergedAnnotationAttributes(AnnotatedElement, String, boolean, boolean) */ + @Nullable public static AnnotationAttributes findMergedAnnotationAttributes(AnnotatedElement element, Class annotationType, boolean classValuesAsString, boolean nestedAnnotationsAsMap) { @@ -668,6 +678,7 @@ public class AnnotatedElementUtils { * @see #findMergedAnnotation(AnnotatedElement, Class) * @see #getMergedAnnotationAttributes(AnnotatedElement, String, boolean, boolean) */ + @Nullable public static AnnotationAttributes findMergedAnnotationAttributes(AnnotatedElement element, String annotationName, boolean classValuesAsString, boolean nestedAnnotationsAsMap) { @@ -695,6 +706,7 @@ public class AnnotatedElementUtils { * @see #findMergedAnnotationAttributes(AnnotatedElement, String, boolean, boolean) * @see #getMergedAnnotationAttributes(AnnotatedElement, Class) */ + @Nullable public static A findMergedAnnotation(AnnotatedElement element, Class annotationType) { Assert.notNull(annotationType, "'annotationType' must not be null"); @@ -800,7 +812,7 @@ public class AnnotatedElementUtils { * is not a valid container annotation for the supplied {@code annotationType} */ public static Set findMergedRepeatableAnnotations(AnnotatedElement element, - Class annotationType, Class containerType) { + Class annotationType, @Nullable Class containerType) { Assert.notNull(element, "AnnotatedElement must not be null"); Assert.notNull(annotationType, "'annotationType' must not be null"); @@ -828,6 +840,7 @@ public class AnnotatedElementUtils { * @param processor the processor to delegate to * @return the result of the processor, potentially {@code null} */ + @Nullable private static T searchWithGetSemantics(AnnotatedElement element, Class annotationType, String annotationName, Processor processor) { @@ -848,8 +861,9 @@ public class AnnotatedElementUtils { * @return the result of the processor, potentially {@code null} * @since 4.3 */ + @Nullable private static T searchWithGetSemantics(AnnotatedElement element, Class annotationType, - String annotationName, Class containerType, Processor processor) { + String annotationName, @Nullable Class containerType, Processor processor) { try { return searchWithGetSemantics(element, annotationType, annotationName, containerType, processor, @@ -878,8 +892,9 @@ public class AnnotatedElementUtils { * @param metaDepth the meta-depth of the annotation * @return the result of the processor, potentially {@code null} */ + @Nullable private static T searchWithGetSemantics(AnnotatedElement element, Class annotationType, - String annotationName, Class containerType, Processor processor, + String annotationName, @Nullable Class containerType, Processor processor, Set visited, int metaDepth) { Assert.notNull(element, "AnnotatedElement must not be null"); @@ -940,9 +955,10 @@ public class AnnotatedElementUtils { * @return the result of the processor, potentially {@code null} * @since 4.2 */ - private static T searchWithGetSemanticsInAnnotations(AnnotatedElement element, + @Nullable + private static T searchWithGetSemanticsInAnnotations(@Nullable AnnotatedElement element, List annotations, Class annotationType, String annotationName, - Class containerType, Processor processor, Set visited, + @Nullable Class containerType, Processor processor, Set visited, int metaDepth) { // Search in annotations @@ -1009,6 +1025,7 @@ public class AnnotatedElementUtils { * @return the result of the processor, potentially {@code null} * @since 4.2 */ + @Nullable private static T searchWithFindSemantics(AnnotatedElement element, Class annotationType, String annotationName, Processor processor) { @@ -1029,8 +1046,9 @@ public class AnnotatedElementUtils { * @return the result of the processor, potentially {@code null} * @since 4.3 */ + @Nullable private static T searchWithFindSemantics(AnnotatedElement element, Class annotationType, - String annotationName, Class containerType, Processor processor) { + String annotationName, @Nullable Class containerType, Processor processor) { if (containerType != null && !processor.aggregates()) { throw new IllegalArgumentException( @@ -1065,8 +1083,9 @@ public class AnnotatedElementUtils { * @return the result of the processor, potentially {@code null} * @since 4.2 */ + @Nullable private static T searchWithFindSemantics(AnnotatedElement element, Class annotationType, - String annotationName, Class containerType, Processor processor, + String annotationName, @Nullable Class containerType, Processor processor, Set visited, int metaDepth) { Assert.notNull(element, "AnnotatedElement must not be null"); @@ -1365,7 +1384,8 @@ public class AnnotatedElementUtils { * @return the result of the processing, or {@code null} to continue * searching for additional annotations */ - T process(AnnotatedElement annotatedElement, Annotation annotation, int metaDepth); + @Nullable + T process(@Nullable AnnotatedElement annotatedElement, Annotation annotation, int metaDepth); /** * Post-process the result returned by the {@link #process} method. @@ -1379,7 +1399,7 @@ public class AnnotatedElementUtils { * @param annotation the annotation to post-process * @param result the result to post-process */ - void postProcess(AnnotatedElement annotatedElement, Annotation annotation, T result); + void postProcess(@Nullable AnnotatedElement annotatedElement, Annotation annotation, T result); /** * Determine if this processor always processes annotations regardless of diff --git a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationAttributeExtractor.java b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationAttributeExtractor.java index 7fd8dd4263..c8f2ae0c35 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationAttributeExtractor.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationAttributeExtractor.java @@ -19,6 +19,8 @@ package org.springframework.core.annotation; import java.lang.annotation.Annotation; import java.lang.reflect.Method; +import org.springframework.lang.Nullable; + /** * An {@code AnnotationAttributeExtractor} is responsible for * {@linkplain #getAttributeValue extracting} annotation attribute values @@ -43,6 +45,7 @@ interface AnnotationAttributeExtractor { * type supported by this extractor. * @return the annotated element, or {@code null} if unknown */ + @Nullable Object getAnnotatedElement(); /** diff --git a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationAttributes.java b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationAttributes.java index 9a53474edd..7c98e51341 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationAttributes.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationAttributes.java @@ -22,6 +22,7 @@ import java.util.Iterator; import java.util.LinkedHashMap; import java.util.Map; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -120,7 +121,7 @@ public class AnnotationAttributes extends LinkedHashMap { * or {@code null} to just store the annotation type name * @since 4.3.2 */ - public AnnotationAttributes(String annotationType, ClassLoader classLoader) { + public AnnotationAttributes(String annotationType, @Nullable ClassLoader classLoader) { Assert.notNull(annotationType, "'annotationType' must not be null"); this.annotationType = getAnnotationType(annotationType, classLoader); this.displayName = annotationType; @@ -146,6 +147,7 @@ public class AnnotationAttributes extends LinkedHashMap { * @return the annotation type, or {@code null} if unknown * @since 4.2 */ + @Nullable public Class annotationType() { return this.annotationType; } diff --git a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java index 6511262b84..fa9d6b0bca 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java @@ -38,6 +38,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.core.BridgeMethodResolver; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ConcurrentReferenceHashMap; import org.springframework.util.ObjectUtils; @@ -151,6 +152,7 @@ public abstract class AnnotationUtils { * @since 4.0 */ @SuppressWarnings("unchecked") + @Nullable public static A getAnnotation(Annotation ann, Class annotationType) { if (annotationType.isInstance(ann)) { return synthesizeAnnotation((A) ann); @@ -177,6 +179,7 @@ public abstract class AnnotationUtils { * @return the first matching annotation, or {@code null} if not found * @since 3.1 */ + @Nullable public static A getAnnotation(AnnotatedElement annotatedElement, Class annotationType) { try { A annotation = annotatedElement.getAnnotation(annotationType); @@ -210,6 +213,7 @@ public abstract class AnnotationUtils { * @see org.springframework.core.BridgeMethodResolver#findBridgedMethod(Method) * @see #getAnnotation(AnnotatedElement, Class) */ + @Nullable public static A getAnnotation(Method method, Class annotationType) { Method resolvedMethod = BridgeMethodResolver.findBridgedMethod(method); return getAnnotation((AnnotatedElement) resolvedMethod, annotationType); @@ -226,6 +230,7 @@ public abstract class AnnotationUtils { * @since 4.0.8 * @see AnnotatedElement#getAnnotations() */ + @Nullable public static Annotation[] getAnnotations(AnnotatedElement annotatedElement) { try { return synthesizeAnnotationArray(annotatedElement.getAnnotations(), annotatedElement); @@ -248,6 +253,7 @@ public abstract class AnnotationUtils { * @see org.springframework.core.BridgeMethodResolver#findBridgedMethod(Method) * @see AnnotatedElement#getAnnotations() */ + @Nullable public static Annotation[] getAnnotations(Method method) { try { return synthesizeAnnotationArray(BridgeMethodResolver.findBridgedMethod(method).getAnnotations(), method); @@ -285,6 +291,7 @@ public abstract class AnnotationUtils { * @see java.lang.annotation.Repeatable * @see java.lang.reflect.AnnotatedElement#getAnnotationsByType */ + @Nullable public static Set getRepeatableAnnotations(AnnotatedElement annotatedElement, Class annotationType) { @@ -322,7 +329,7 @@ public abstract class AnnotationUtils { * @see java.lang.reflect.AnnotatedElement#getAnnotationsByType */ public static Set getRepeatableAnnotations(AnnotatedElement annotatedElement, - Class annotationType, Class containerAnnotationType) { + Class annotationType, @Nullable Class containerAnnotationType) { Set annotations = getDeclaredRepeatableAnnotations(annotatedElement, annotationType, containerAnnotationType); if (!annotations.isEmpty()) { @@ -404,7 +411,7 @@ public abstract class AnnotationUtils { * @see java.lang.reflect.AnnotatedElement#getDeclaredAnnotationsByType */ public static Set getDeclaredRepeatableAnnotations(AnnotatedElement annotatedElement, - Class annotationType, Class containerAnnotationType) { + Class annotationType, @Nullable Class containerAnnotationType) { return getRepeatableAnnotations(annotatedElement, annotationType, containerAnnotationType, true); } @@ -430,7 +437,7 @@ public abstract class AnnotationUtils { * @see java.lang.annotation.Repeatable */ private static Set getRepeatableAnnotations(AnnotatedElement annotatedElement, - Class annotationType, Class containerAnnotationType, boolean declaredMode) { + Class annotationType, @Nullable Class containerAnnotationType, boolean declaredMode) { Assert.notNull(annotatedElement, "AnnotatedElement must not be null"); Assert.notNull(annotationType, "Annotation type must not be null"); @@ -463,6 +470,7 @@ public abstract class AnnotationUtils { * @return the first matching annotation, or {@code null} if not found * @since 4.2 */ + @Nullable public static A findAnnotation(AnnotatedElement annotatedElement, Class annotationType) { Assert.notNull(annotatedElement, "AnnotatedElement must not be null"); if (annotationType == null) { @@ -485,6 +493,7 @@ public abstract class AnnotationUtils { * @return the first matching annotation, or {@code null} if not found * @since 4.2 */ + @Nullable private static A findAnnotation( AnnotatedElement annotatedElement, Class annotationType, Set visited) { try { @@ -524,6 +533,7 @@ public abstract class AnnotationUtils { * @see #getAnnotation(Method, Class) */ @SuppressWarnings("unchecked") + @Nullable public static A findAnnotation(Method method, Class annotationType) { Assert.notNull(method, "Method must not be null"); if (annotationType == null) { @@ -631,6 +641,7 @@ public abstract class AnnotationUtils { * @param annotationType the type of annotation to look for * @return the first matching annotation, or {@code null} if not found */ + @Nullable public static A findAnnotation(Class clazz, Class annotationType) { return findAnnotation(clazz, annotationType, true); } @@ -646,6 +657,7 @@ public abstract class AnnotationUtils { * @since 4.2.1 */ @SuppressWarnings("unchecked") + @Nullable private static A findAnnotation(Class clazz, Class annotationType, boolean synthesize) { Assert.notNull(clazz, "Class must not be null"); if (annotationType == null) { @@ -673,6 +685,7 @@ public abstract class AnnotationUtils { * @param visited the set of annotations that have already been visited * @return the first matching annotation, or {@code null} if not found */ + @Nullable private static A findAnnotation(Class clazz, Class annotationType, Set visited) { try { A annotation = clazz.getDeclaredAnnotation(annotationType); @@ -730,7 +743,8 @@ public abstract class AnnotationUtils { * @see #findAnnotationDeclaringClassForTypes(List, Class) * @see #isAnnotationDeclaredLocally(Class, Class) */ - public static Class findAnnotationDeclaringClass(Class annotationType, Class clazz) { + @Nullable + public static Class findAnnotationDeclaringClass(Class annotationType, @Nullable Class clazz) { Assert.notNull(annotationType, "Annotation type must not be null"); if (clazz == null || Object.class == clazz) { return null; @@ -765,7 +779,8 @@ public abstract class AnnotationUtils { * @see #findAnnotationDeclaringClass(Class, Class) * @see #isAnnotationDeclaredLocally(Class, Class) */ - public static Class findAnnotationDeclaringClassForTypes(List> annotationTypes, Class clazz) { + @Nullable + public static Class findAnnotationDeclaringClassForTypes(List> annotationTypes, @Nullable Class clazz) { Assert.notEmpty(annotationTypes, "List of annotation types must not be empty"); if (clazz == null || Object.class == clazz) { return null; @@ -966,7 +981,7 @@ public abstract class AnnotationUtils { * @since 4.2 * @see #getAnnotationAttributes(AnnotatedElement, Annotation, boolean, boolean) */ - public static AnnotationAttributes getAnnotationAttributes(AnnotatedElement annotatedElement, Annotation annotation) { + public static AnnotationAttributes getAnnotationAttributes(@Nullable AnnotatedElement annotatedElement, Annotation annotation) { return getAnnotationAttributes(annotatedElement, annotation, false, false); } @@ -988,7 +1003,7 @@ public abstract class AnnotationUtils { * and corresponding attribute values as values (never {@code null}) * @since 4.2 */ - public static AnnotationAttributes getAnnotationAttributes(AnnotatedElement annotatedElement, + public static AnnotationAttributes getAnnotationAttributes(@Nullable AnnotatedElement annotatedElement, Annotation annotation, boolean classValuesAsString, boolean nestedAnnotationsAsMap) { return getAnnotationAttributes( @@ -1032,7 +1047,7 @@ public abstract class AnnotationUtils { * @since 4.2 * @see #postProcessAnnotationAttributes */ - static AnnotationAttributes retrieveAnnotationAttributes(Object annotatedElement, Annotation annotation, + static AnnotationAttributes retrieveAnnotationAttributes(@Nullable Object annotatedElement, Annotation annotation, boolean classValuesAsString, boolean nestedAnnotationsAsMap) { Class annotationType = annotation.annotationType(); @@ -1076,7 +1091,7 @@ public abstract class AnnotationUtils { * {@code Annotation} instances * @return the adapted value, or the original value if no adaptation is needed */ - static Object adaptValue(Object annotatedElement, Object value, boolean classValuesAsString, + static Object adaptValue(@Nullable Object annotatedElement, Object value, boolean classValuesAsString, boolean nestedAnnotationsAsMap) { if (classValuesAsString) { @@ -1173,7 +1188,7 @@ public abstract class AnnotationUtils { * @see #postProcessAnnotationAttributes(Object, AnnotationAttributes, boolean, boolean) * @see #getDefaultValue(Class, String) */ - public static void postProcessAnnotationAttributes(Object annotatedElement, + public static void postProcessAnnotationAttributes(@Nullable Object annotatedElement, AnnotationAttributes attributes, boolean classValuesAsString) { postProcessAnnotationAttributes(annotatedElement, attributes, classValuesAsString, false); @@ -1199,7 +1214,7 @@ public abstract class AnnotationUtils { * @see #retrieveAnnotationAttributes(Object, Annotation, boolean, boolean) * @see #getDefaultValue(Class, String) */ - static void postProcessAnnotationAttributes(Object annotatedElement, + static void postProcessAnnotationAttributes(@Nullable Object annotatedElement, AnnotationAttributes attributes, boolean classValuesAsString, boolean nestedAnnotationsAsMap) { // Abort? @@ -1287,6 +1302,7 @@ public abstract class AnnotationUtils { * in which case such an exception will be rethrown * @see #getValue(Annotation, String) */ + @Nullable public static Object getValue(Annotation annotation) { return getValue(annotation, VALUE); } @@ -1301,6 +1317,7 @@ public abstract class AnnotationUtils { * @see #getValue(Annotation) * @see #rethrowAnnotationConfigurationException(Throwable) */ + @Nullable public static Object getValue(Annotation annotation, String attributeName) { if (annotation == null || !StringUtils.hasText(attributeName)) { return null; @@ -1328,6 +1345,7 @@ public abstract class AnnotationUtils { * @return the default value, or {@code null} if not found * @see #getDefaultValue(Annotation, String) */ + @Nullable public static Object getDefaultValue(Annotation annotation) { return getDefaultValue(annotation, VALUE); } @@ -1339,6 +1357,7 @@ public abstract class AnnotationUtils { * @return the default value of the named attribute, or {@code null} if not found * @see #getDefaultValue(Class, String) */ + @Nullable public static Object getDefaultValue(Annotation annotation, String attributeName) { if (annotation == null) { return null; @@ -1353,6 +1372,7 @@ public abstract class AnnotationUtils { * @return the default value, or {@code null} if not found * @see #getDefaultValue(Class, String) */ + @Nullable public static Object getDefaultValue(Class annotationType) { return getDefaultValue(annotationType, VALUE); } @@ -1365,6 +1385,7 @@ public abstract class AnnotationUtils { * @return the default value of the named attribute, or {@code null} if not found * @see #getDefaultValue(Annotation, String) */ + @Nullable public static Object getDefaultValue(Class annotationType, String attributeName) { if (annotationType == null || !StringUtils.hasText(attributeName)) { return null; @@ -1392,7 +1413,8 @@ public abstract class AnnotationUtils { * @since 4.2 * @see #synthesizeAnnotation(Annotation, AnnotatedElement) */ - static A synthesizeAnnotation(A annotation) { + @Nullable + static A synthesizeAnnotation(@Nullable A annotation) { return synthesizeAnnotation(annotation, null); } @@ -1413,7 +1435,8 @@ public abstract class AnnotationUtils { * @see #synthesizeAnnotation(Map, Class, AnnotatedElement) * @see #synthesizeAnnotation(Class) */ - public static A synthesizeAnnotation(A annotation, AnnotatedElement annotatedElement) { + @Nullable + public static A synthesizeAnnotation(A annotation, @Nullable AnnotatedElement annotatedElement) { return synthesizeAnnotation(annotation, (Object) annotatedElement); } @@ -1472,8 +1495,9 @@ public abstract class AnnotationUtils { * @see #getAnnotationAttributes(AnnotatedElement, Annotation, boolean, boolean) */ @SuppressWarnings("unchecked") + @Nullable public static A synthesizeAnnotation(Map attributes, - Class annotationType, AnnotatedElement annotatedElement) { + Class annotationType, @Nullable AnnotatedElement annotatedElement) { Assert.notNull(annotationType, "'annotationType' must not be null"); if (attributes == null) { @@ -1503,6 +1527,7 @@ public abstract class AnnotationUtils { * @see #synthesizeAnnotation(Map, Class, AnnotatedElement) * @see #synthesizeAnnotation(Annotation, AnnotatedElement) */ + @Nullable public static A synthesizeAnnotation(Class annotationType) { return synthesizeAnnotation(Collections. emptyMap(), annotationType, null); } @@ -1523,7 +1548,8 @@ public abstract class AnnotationUtils { * @see #synthesizeAnnotation(Annotation, AnnotatedElement) * @see #synthesizeAnnotation(Map, Class, AnnotatedElement) */ - static Annotation[] synthesizeAnnotationArray(Annotation[] annotations, Object annotatedElement) { + @Nullable + static Annotation[] synthesizeAnnotationArray(@Nullable Annotation[] annotations, @Nullable Object annotatedElement) { if (annotations == null) { return null; } @@ -1554,7 +1580,8 @@ public abstract class AnnotationUtils { * @see #synthesizeAnnotationArray(Annotation[], Object) */ @SuppressWarnings("unchecked") - static A[] synthesizeAnnotationArray(Map[] maps, Class annotationType) { + @Nullable + static A[] synthesizeAnnotationArray(@Nullable Map[] maps, Class annotationType) { Assert.notNull(annotationType, "'annotationType' must not be null"); if (maps == null) { return null; @@ -1705,7 +1732,8 @@ public abstract class AnnotationUtils { * {@code @AliasFor} is detected * @since 4.2 */ - static String getAttributeOverrideName(Method attribute, Class metaAnnotationType) { + @Nullable + static String getAttributeOverrideName(Method attribute, @Nullable Class metaAnnotationType) { Assert.notNull(attribute, "attribute must not be null"); Assert.notNull(metaAnnotationType, "metaAnnotationType must not be null"); Assert.isTrue(Annotation.class != metaAnnotationType, @@ -1753,6 +1781,7 @@ public abstract class AnnotationUtils { * @return the annotation if found; {@code null} otherwise * @since 4.2 */ + @Nullable static Annotation getAnnotation(AnnotatedElement element, String annotationName) { for (Annotation annotation : element.getAnnotations()) { if (annotation.annotationType().getName().equals(annotationName)) { @@ -1790,6 +1819,7 @@ public abstract class AnnotationUtils { * {@code null}. * @since 4.2 */ + @Nullable static Class resolveContainerAnnotationType(Class annotationType) { Repeatable repeatable = getAnnotation(annotationType, Repeatable.class); return (repeatable != null ? repeatable.value() : null); @@ -1994,6 +2024,7 @@ public abstract class AnnotationUtils { * is not annotated with {@code @AliasFor} * @see #validateAgainst */ + @Nullable public static AliasDescriptor from(Method attribute) { AliasDescriptor descriptor = aliasDescriptorCache.get(attribute); if (descriptor != null) { @@ -2180,6 +2211,7 @@ public abstract class AnnotationUtils { return otherDescriptors; } + @Nullable public String getAttributeOverrideName(Class metaAnnotationType) { Assert.notNull(metaAnnotationType, "metaAnnotationType must not be null"); Assert.isTrue(Annotation.class != metaAnnotationType, @@ -2196,6 +2228,7 @@ public abstract class AnnotationUtils { return null; } + @Nullable private AliasDescriptor getAttributeOverrideDescriptor() { if (this.isAliasPair) { return null; @@ -2219,6 +2252,7 @@ public abstract class AnnotationUtils { * @throws AnnotationConfigurationException if invalid configuration of * {@code @AliasFor} is detected */ + @Nullable private String getAliasedAttributeName(AliasFor aliasFor, Method attribute) { String attributeName = aliasFor.attribute(); String value = aliasFor.value(); diff --git a/spring-core/src/main/java/org/springframework/core/annotation/DefaultAnnotationAttributeExtractor.java b/spring-core/src/main/java/org/springframework/core/annotation/DefaultAnnotationAttributeExtractor.java index 0ea2cf0013..35046ad4fc 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/DefaultAnnotationAttributeExtractor.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/DefaultAnnotationAttributeExtractor.java @@ -19,6 +19,7 @@ package org.springframework.core.annotation; import java.lang.annotation.Annotation; import java.lang.reflect.Method; +import org.springframework.lang.Nullable; import org.springframework.util.ReflectionUtils; /** @@ -41,7 +42,7 @@ class DefaultAnnotationAttributeExtractor extends AbstractAliasAwareAnnotationAt * @param annotatedElement the element that is annotated with the supplied * annotation; may be {@code null} if unknown */ - DefaultAnnotationAttributeExtractor(Annotation annotation, Object annotatedElement) { + DefaultAnnotationAttributeExtractor(Annotation annotation, @Nullable Object annotatedElement) { super(annotation.annotationType(), annotatedElement, annotation); } diff --git a/spring-core/src/main/java/org/springframework/core/annotation/MapAnnotationAttributeExtractor.java b/spring-core/src/main/java/org/springframework/core/annotation/MapAnnotationAttributeExtractor.java index 24bdb15dc1..e88c502083 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/MapAnnotationAttributeExtractor.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/MapAnnotationAttributeExtractor.java @@ -24,6 +24,7 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; @@ -52,7 +53,7 @@ class MapAnnotationAttributeExtractor extends AbstractAliasAwareAnnotationAttrib * of the supplied type; may be {@code null} if unknown */ MapAnnotationAttributeExtractor(Map attributes, Class annotationType, - AnnotatedElement annotatedElement) { + @Nullable AnnotatedElement annotatedElement) { super(annotationType, annotatedElement, enrichAndValidateAttributes(attributes, annotationType)); } diff --git a/spring-core/src/main/java/org/springframework/core/annotation/OrderUtils.java b/spring-core/src/main/java/org/springframework/core/annotation/OrderUtils.java index 5b2cf361fe..0109c39a43 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/OrderUtils.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/OrderUtils.java @@ -18,6 +18,7 @@ package org.springframework.core.annotation; import java.lang.annotation.Annotation; +import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; /** @@ -53,6 +54,7 @@ public abstract class OrderUtils { * @return the order value, or {@code null} if none can be found * @see #getPriority(Class) */ + @Nullable public static Integer getOrder(Class type) { return getOrder(type, null); } @@ -83,6 +85,7 @@ public abstract class OrderUtils { * @param type the type to handle * @return the priority value if the annotation is declared, or {@code null} if none */ + @Nullable public static Integer getPriority(Class type) { if (priorityAnnotationType != null) { Annotation priority = AnnotationUtils.findAnnotation(type, priorityAnnotationType); diff --git a/spring-core/src/main/java/org/springframework/core/annotation/package-info.java b/spring-core/src/main/java/org/springframework/core/annotation/package-info.java index 6aceac2c80..3715a52176 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/package-info.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/package-info.java @@ -2,4 +2,7 @@ * Core support package for annotations, meta-annotations, and composed * annotations with attribute overrides. */ +@NonNullApi package org.springframework.core.annotation; + +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-core/src/main/java/org/springframework/core/codec/CodecException.java b/spring-core/src/main/java/org/springframework/core/codec/CodecException.java index 64ee902238..07ef2a66f3 100644 --- a/spring-core/src/main/java/org/springframework/core/codec/CodecException.java +++ b/spring-core/src/main/java/org/springframework/core/codec/CodecException.java @@ -17,6 +17,7 @@ package org.springframework.core.codec; import org.springframework.core.NestedRuntimeException; +import org.springframework.lang.Nullable; /** * General error that indicates a problem while encoding and decoding to and @@ -42,7 +43,7 @@ public class CodecException extends NestedRuntimeException { * @param msg the detail message * @param cause root cause for the exception, if any */ - public CodecException(String msg, Throwable cause) { + public CodecException(String msg, @Nullable Throwable cause) { super(msg, cause); } diff --git a/spring-core/src/main/java/org/springframework/core/codec/Decoder.java b/spring-core/src/main/java/org/springframework/core/codec/Decoder.java index 21fce51ac4..4f8583ef64 100644 --- a/spring-core/src/main/java/org/springframework/core/codec/Decoder.java +++ b/spring-core/src/main/java/org/springframework/core/codec/Decoder.java @@ -25,6 +25,7 @@ import reactor.core.publisher.Mono; import org.springframework.core.ResolvableType; import org.springframework.core.io.buffer.DataBuffer; +import org.springframework.lang.Nullable; import org.springframework.util.MimeType; /** @@ -45,7 +46,7 @@ public interface Decoder { * @param mimeType the mime type associated with the stream to decode, can be {@code null} if not specified. * @return {@code true} if supported, {@code false} otherwise */ - boolean canDecode(ResolvableType elementType, MimeType mimeType); + boolean canDecode(ResolvableType elementType, @Nullable MimeType mimeType); /** * Decode a {@link DataBuffer} input stream into a Flux of {@code T}. @@ -58,7 +59,7 @@ public interface Decoder { * @return the output stream with decoded elements */ Flux decode(Publisher inputStream, ResolvableType elementType, - MimeType mimeType, Map hints); + @Nullable MimeType mimeType, Map hints); /** * Decode a {@link DataBuffer} input stream into a Mono of {@code T}. @@ -71,7 +72,7 @@ public interface Decoder { * @return the output stream with the decoded element */ Mono decodeToMono(Publisher inputStream, ResolvableType elementType, - MimeType mimeType, Map hints); + @Nullable MimeType mimeType, Map hints); /** * Return the list of MIME types this decoder supports. diff --git a/spring-core/src/main/java/org/springframework/core/codec/DecodingException.java b/spring-core/src/main/java/org/springframework/core/codec/DecodingException.java index 3cf4b62f3e..b49462d679 100644 --- a/spring-core/src/main/java/org/springframework/core/codec/DecodingException.java +++ b/spring-core/src/main/java/org/springframework/core/codec/DecodingException.java @@ -15,6 +15,8 @@ */ package org.springframework.core.codec; +import org.springframework.lang.Nullable; + /** * Indicates an issue with decoding the input stream with a focus on content * related issues such as a parse failure. As opposed to more general I/O @@ -45,7 +47,7 @@ public class DecodingException extends CodecException { * @param msg the detail message * @param cause root cause for the exception, if any */ - public DecodingException(String msg, Throwable cause) { + public DecodingException(String msg, @Nullable Throwable cause) { super(msg, cause); } diff --git a/spring-core/src/main/java/org/springframework/core/codec/Encoder.java b/spring-core/src/main/java/org/springframework/core/codec/Encoder.java index 96c6352deb..65773e4a4e 100644 --- a/spring-core/src/main/java/org/springframework/core/codec/Encoder.java +++ b/spring-core/src/main/java/org/springframework/core/codec/Encoder.java @@ -26,6 +26,7 @@ import reactor.core.publisher.Mono; import org.springframework.core.ResolvableType; import org.springframework.core.io.buffer.DataBuffer; import org.springframework.core.io.buffer.DataBufferFactory; +import org.springframework.lang.Nullable; import org.springframework.util.MimeType; /** @@ -46,7 +47,7 @@ public interface Encoder { * @param mimeType the MIME type for the output stream, can be {@code null} if not specified. * @return {@code true} if supported, {@code false} otherwise */ - boolean canEncode(ResolvableType elementType, MimeType mimeType); + boolean canEncode(ResolvableType elementType, @Nullable MimeType mimeType); /** * Encode a stream of Objects of type {@code T} into a {@link DataBuffer} @@ -63,7 +64,7 @@ public interface Encoder { * @return the output stream */ Flux encode(Publisher inputStream, DataBufferFactory bufferFactory, - ResolvableType elementType, MimeType mimeType, Map hints); + ResolvableType elementType, @Nullable MimeType mimeType, Map hints); /** * Return the list of mime types this encoder supports. diff --git a/spring-core/src/main/java/org/springframework/core/codec/EncodingException.java b/spring-core/src/main/java/org/springframework/core/codec/EncodingException.java index f987adb1c3..9dbdb26c44 100644 --- a/spring-core/src/main/java/org/springframework/core/codec/EncodingException.java +++ b/spring-core/src/main/java/org/springframework/core/codec/EncodingException.java @@ -15,6 +15,8 @@ */ package org.springframework.core.codec; +import org.springframework.lang.Nullable; + /** * Indicates an issue with encoding the input Object stream with a focus on * not being able to encode Objects. As opposed to a more general I/O errors @@ -41,7 +43,7 @@ public class EncodingException extends CodecException { * @param msg the detail message * @param cause root cause for the exception, if any */ - public EncodingException(String msg, Throwable cause) { + public EncodingException(String msg, @Nullable Throwable cause) { super(msg, cause); } diff --git a/spring-core/src/main/java/org/springframework/core/codec/package-info.java b/spring-core/src/main/java/org/springframework/core/codec/package-info.java index c18d25b5ab..5a35824df1 100644 --- a/spring-core/src/main/java/org/springframework/core/codec/package-info.java +++ b/spring-core/src/main/java/org/springframework/core/codec/package-info.java @@ -3,4 +3,7 @@ * {@link org.springframework.core.codec.Decoder} abstractions to convert * between a reactive stream of bytes and Java objects. */ +@NonNullApi package org.springframework.core.codec; + +import org.springframework.lang.NonNullApi; diff --git a/spring-core/src/main/java/org/springframework/core/convert/ConversionService.java b/spring-core/src/main/java/org/springframework/core/convert/ConversionService.java index 382e5ad353..59c8eb65d6 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/ConversionService.java +++ b/spring-core/src/main/java/org/springframework/core/convert/ConversionService.java @@ -16,6 +16,8 @@ package org.springframework.core.convert; +import org.springframework.lang.Nullable; + /** * A service interface for type conversion. This is the entry point into the convert system. * Call {@link #convert(Object, Class)} to perform a thread-safe type conversion using this system. @@ -40,7 +42,7 @@ public interface ConversionService { * @return {@code true} if a conversion can be performed, {@code false} if not * @throws IllegalArgumentException if {@code targetType} is {@code null} */ - boolean canConvert(Class sourceType, Class targetType); + boolean canConvert(@Nullable Class sourceType, Class targetType); /** * Return {@code true} if objects of {@code sourceType} can be converted to the {@code targetType}. @@ -60,7 +62,7 @@ public interface ConversionService { * {@code false} if not * @throws IllegalArgumentException if {@code targetType} is {@code null} */ - boolean canConvert(TypeDescriptor sourceType, TypeDescriptor targetType); + boolean canConvert(@Nullable TypeDescriptor sourceType, TypeDescriptor targetType); /** * Convert the given {@code source} to the specified {@code targetType}. @@ -70,7 +72,7 @@ public interface ConversionService { * @throws ConversionException if a conversion exception occurred * @throws IllegalArgumentException if targetType is {@code null} */ - T convert(Object source, Class targetType); + T convert(@Nullable Object source, Class targetType); /** * Convert the given {@code source} to the specified {@code targetType}. @@ -85,6 +87,6 @@ public interface ConversionService { * @throws IllegalArgumentException if targetType is {@code null}, * or {@code sourceType} is {@code null} but source is not {@code null} */ - Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType); + Object convert(@Nullable Object source, @Nullable TypeDescriptor sourceType, TypeDescriptor targetType); } diff --git a/spring-core/src/main/java/org/springframework/core/convert/Property.java b/spring-core/src/main/java/org/springframework/core/convert/Property.java index 86f8816cbb..ab92578c28 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/Property.java +++ b/spring-core/src/main/java/org/springframework/core/convert/Property.java @@ -25,6 +25,7 @@ import java.util.Map; import org.springframework.core.GenericTypeResolver; import org.springframework.core.MethodParameter; +import org.springframework.lang.Nullable; import org.springframework.util.ConcurrentReferenceHashMap; import org.springframework.util.ObjectUtils; import org.springframework.util.ReflectionUtils; @@ -171,6 +172,7 @@ public final class Property { return write; } + @Nullable private MethodParameter resolveReadMethodParameter() { if (getReadMethod() == null) { return null; @@ -178,6 +180,7 @@ public final class Property { return resolveParameterType(new MethodParameter(getReadMethod(), -1)); } + @Nullable private MethodParameter resolveWriteMethodParameter() { if (getWriteMethod() == null) { return null; @@ -214,6 +217,7 @@ public final class Property { } } + @Nullable private Field getField() { String name = getName(); if (!StringUtils.hasLength(name)) { diff --git a/spring-core/src/main/java/org/springframework/core/convert/TypeDescriptor.java b/spring-core/src/main/java/org/springframework/core/convert/TypeDescriptor.java index 6b1a9f0e6c..79bba13972 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/TypeDescriptor.java +++ b/spring-core/src/main/java/org/springframework/core/convert/TypeDescriptor.java @@ -30,6 +30,7 @@ import java.util.stream.Stream; import org.springframework.core.MethodParameter; import org.springframework.core.ResolvableType; import org.springframework.core.annotation.AnnotatedElementUtils; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.ObjectUtils; @@ -117,7 +118,7 @@ public class TypeDescriptor implements Serializable { * @param annotations the type annotations * @since 4.0 */ - protected TypeDescriptor(ResolvableType resolvableType, Class type, Annotation[] annotations) { + protected TypeDescriptor(ResolvableType resolvableType, @Nullable Class type, Annotation[] annotations) { this.resolvableType = resolvableType; this.type = (type != null ? type : resolvableType.resolve(Object.class)); this.annotatedElement = new AnnotatedElementAdapter(annotations); @@ -181,7 +182,7 @@ public class TypeDescriptor implements Serializable { * @return this TypeDescriptor narrowed (returns a copy with its type updated to the * class of the provided value) */ - public TypeDescriptor narrow(Object value) { + public TypeDescriptor narrow(@Nullable Object value) { if (value == null) { return this; } @@ -197,7 +198,8 @@ public class TypeDescriptor implements Serializable { * @throws IllegalArgumentException if this type is not assignable to the super-type * @since 3.2 */ - public TypeDescriptor upcast(Class superType) { + @Nullable + public TypeDescriptor upcast(@Nullable Class superType) { if (superType == null) { return null; } @@ -250,6 +252,7 @@ public class TypeDescriptor implements Serializable { * @return the annotation, or {@code null} if no such annotation exists on this type descriptor */ @SuppressWarnings("unchecked") + @Nullable public T getAnnotation(Class annotationType) { if (this.annotatedElement.isEmpty()) { // Shortcut: AnnotatedElementUtils would have to expect AnnotatedElement.getAnnotations() @@ -323,6 +326,7 @@ public class TypeDescriptor implements Serializable { * Collection but its element type is not parameterized * @throws IllegalStateException if this type is not a {@code java.util.Collection} or array type */ + @Nullable public TypeDescriptor getElementTypeDescriptor() { if (getResolvableType().isArray()) { return new TypeDescriptor(getResolvableType().getComponentType(), null, getAnnotations()); @@ -370,6 +374,7 @@ public class TypeDescriptor implements Serializable { * but its key type is not parameterized * @throws IllegalStateException if this type is not a {@code java.util.Map} */ + @Nullable public TypeDescriptor getMapKeyTypeDescriptor() { Assert.state(isMap(), "Not a [java.util.Map]"); return getRelatedIfResolvable(this, getResolvableType().asMap().getGeneric(0)); @@ -405,6 +410,7 @@ public class TypeDescriptor implements Serializable { * but its value type is not parameterized * @throws IllegalStateException if this type is not a {@code java.util.Map} */ + @Nullable public TypeDescriptor getMapValueTypeDescriptor() { Assert.state(isMap(), "Not a [java.util.Map]"); return getRelatedIfResolvable(this, getResolvableType().asMap().getGeneric(1)); @@ -431,6 +437,7 @@ public class TypeDescriptor implements Serializable { return narrow(mapValue, getMapValueTypeDescriptor()); } + @Nullable private TypeDescriptor narrow(Object value, TypeDescriptor typeDescriptor) { if (typeDescriptor != null) { return typeDescriptor.narrow(value); @@ -517,7 +524,8 @@ public class TypeDescriptor implements Serializable { * @param source the source object * @return the type descriptor */ - public static TypeDescriptor forObject(Object source) { + @Nullable + public static TypeDescriptor forObject(@Nullable Object source) { return (source != null ? valueOf(source.getClass()) : null); } @@ -531,7 +539,7 @@ public class TypeDescriptor implements Serializable { * @param type the class (may be {@code null} to indicate {@code Object.class}) * @return the corresponding type descriptor */ - public static TypeDescriptor valueOf(Class type) { + public static TypeDescriptor valueOf(@Nullable Class type) { if (type == null) { type = Object.class; } @@ -594,7 +602,8 @@ public class TypeDescriptor implements Serializable { * @return an array {@link TypeDescriptor} or {@code null} if {@code elementTypeDescriptor} is {@code null} * @since 3.2.1 */ - public static TypeDescriptor array(TypeDescriptor elementTypeDescriptor) { + @Nullable + public static TypeDescriptor array(@Nullable TypeDescriptor elementTypeDescriptor) { if (elementTypeDescriptor == null) { return null; } @@ -624,6 +633,7 @@ public class TypeDescriptor implements Serializable { * {@link MethodParameter} argument is not 1, or if the types up to the * specified nesting level are not of collection, array, or map types */ + @Nullable public static TypeDescriptor nested(MethodParameter methodParameter, int nestingLevel) { if (methodParameter.getNestingLevel() != 1) { throw new IllegalArgumentException("MethodParameter nesting level must be 1: " + @@ -652,6 +662,7 @@ public class TypeDescriptor implements Serializable { * @throws IllegalArgumentException if the types up to the specified nesting * level are not of collection, array, or map types */ + @Nullable public static TypeDescriptor nested(Field field, int nestingLevel) { return nested(new TypeDescriptor(field), nestingLevel); } @@ -677,10 +688,12 @@ public class TypeDescriptor implements Serializable { * @throws IllegalArgumentException if the types up to the specified nesting * level are not of collection, array, or map types */ + @Nullable public static TypeDescriptor nested(Property property, int nestingLevel) { return nested(new TypeDescriptor(property), nestingLevel); } + @Nullable private static TypeDescriptor nested(TypeDescriptor typeDescriptor, int nestingLevel) { ResolvableType nested = typeDescriptor.resolvableType; for (int i = 0; i < nestingLevel; i++) { @@ -698,6 +711,7 @@ public class TypeDescriptor implements Serializable { return getRelatedIfResolvable(typeDescriptor, nested); } + @Nullable private static TypeDescriptor getRelatedIfResolvable(TypeDescriptor source, ResolvableType type) { if (type.resolve() == null) { return null; diff --git a/spring-core/src/main/java/org/springframework/core/convert/converter/Converter.java b/spring-core/src/main/java/org/springframework/core/convert/converter/Converter.java index 0d3c5dc14f..8b931a6988 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/converter/Converter.java +++ b/spring-core/src/main/java/org/springframework/core/convert/converter/Converter.java @@ -16,6 +16,8 @@ package org.springframework.core.convert.converter; +import org.springframework.lang.Nullable; + /** * A converter converts a source object of type {@code S} to a target of type {@code T}. * @@ -37,6 +39,7 @@ public interface Converter { * @return the converted object, which must be an instance of {@code T} (potentially {@code null}) * @throws IllegalArgumentException if the source cannot be converted to the desired target type */ + @Nullable T convert(S source); } diff --git a/spring-core/src/main/java/org/springframework/core/convert/converter/GenericConverter.java b/spring-core/src/main/java/org/springframework/core/convert/converter/GenericConverter.java index 09d3b10837..e5fc5c420c 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/converter/GenericConverter.java +++ b/spring-core/src/main/java/org/springframework/core/convert/converter/GenericConverter.java @@ -19,6 +19,7 @@ package org.springframework.core.convert.converter; import java.util.Set; import org.springframework.core.convert.TypeDescriptor; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -52,6 +53,7 @@ public interface GenericConverter { *

For {@link ConditionalConverter conditional converters} this method may return * {@code null} to indicate all source-to-target pairs should be considered. */ + @Nullable Set getConvertibleTypes(); /** @@ -61,7 +63,8 @@ public interface GenericConverter { * @param targetType the type descriptor of the field we are converting to * @return the converted object */ - Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType); + @Nullable + Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType); /** diff --git a/spring-core/src/main/java/org/springframework/core/convert/converter/package-info.java b/spring-core/src/main/java/org/springframework/core/convert/converter/package-info.java index 0637484158..d1f79c261b 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/converter/package-info.java +++ b/spring-core/src/main/java/org/springframework/core/convert/converter/package-info.java @@ -1,4 +1,7 @@ /** * SPI to implement Converters for the type conversion system. */ +@NonNullApi package org.springframework.core.convert.converter; + +import org.springframework.lang.NonNullApi; diff --git a/spring-core/src/main/java/org/springframework/core/convert/package-info.java b/spring-core/src/main/java/org/springframework/core/convert/package-info.java index ea94c62614..b63fe0e89f 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/package-info.java +++ b/spring-core/src/main/java/org/springframework/core/convert/package-info.java @@ -1,4 +1,7 @@ /** * Type conversion system API. */ +@NonNullApi package org.springframework.core.convert; + +import org.springframework.lang.NonNullApi; diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java b/spring-core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java index 584600659b..d657bea97a 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java @@ -42,6 +42,7 @@ import org.springframework.core.convert.converter.ConverterFactory; import org.springframework.core.convert.converter.ConverterRegistry; import org.springframework.core.convert.converter.GenericConverter; import org.springframework.core.convert.converter.GenericConverter.ConvertiblePair; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.ConcurrentReferenceHashMap; @@ -157,7 +158,7 @@ public class GenericConversionService implements ConfigurableConversionService { * @throws IllegalArgumentException if targetType is {@code null} * @since 3.2 */ - public boolean canBypassConvert(TypeDescriptor sourceType, TypeDescriptor targetType) { + public boolean canBypassConvert(@Nullable TypeDescriptor sourceType, TypeDescriptor targetType) { Assert.notNull(targetType, "Target type to convert to cannot be null"); if (sourceType == null) { return true; @@ -205,7 +206,8 @@ public class GenericConversionService implements ConfigurableConversionService { * @throws IllegalArgumentException if targetType is {@code null}, * or sourceType is {@code null} but source is not {@code null} */ - public Object convert(Object source, TypeDescriptor targetType) { + @Nullable + public Object convert(@Nullable Object source, TypeDescriptor targetType) { return convert(source, TypeDescriptor.forObject(source), targetType); } @@ -227,6 +229,7 @@ public class GenericConversionService implements ConfigurableConversionService { * @param targetType the target type to convert to * @return the converted null object */ + @Nullable protected Object convertNullSource(TypeDescriptor sourceType, TypeDescriptor targetType) { if (targetType.getObjectType() == Optional.class) { return Optional.empty(); @@ -245,6 +248,7 @@ public class GenericConversionService implements ConfigurableConversionService { * or {@code null} if no suitable converter was found * @see #getDefaultConverter(TypeDescriptor, TypeDescriptor) */ + @Nullable protected GenericConverter getConverter(TypeDescriptor sourceType, TypeDescriptor targetType) { ConverterCacheKey key = new ConverterCacheKey(sourceType, targetType); GenericConverter converter = this.converterCache.get(key); @@ -274,6 +278,7 @@ public class GenericConversionService implements ConfigurableConversionService { * @param targetType the target type to convert to * @return the default generic converter that will perform the conversion */ + @Nullable protected GenericConverter getDefaultConverter(TypeDescriptor sourceType, TypeDescriptor targetType) { return (sourceType.isAssignableTo(targetType) ? NO_OP_CONVERTER : null); } @@ -281,6 +286,7 @@ public class GenericConversionService implements ConfigurableConversionService { // Internal helpers + @Nullable private ResolvableType[] getRequiredTypeInfo(Class converterClass, Class genericIfc) { ResolvableType resolvableType = ResolvableType.forClass(converterClass).as(genericIfc); ResolvableType[] generics = resolvableType.getGenerics(); @@ -299,6 +305,7 @@ public class GenericConversionService implements ConfigurableConversionService { this.converterCache.clear(); } + @Nullable private Object handleConverterNotFound(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { if (source == null) { assertNotPrimitiveTargetType(sourceType, targetType); @@ -526,6 +533,7 @@ public class GenericConversionService implements ConfigurableConversionService { * @param targetType the target type * @return a matching {@link GenericConverter}, or {@code null} if none found */ + @Nullable public GenericConverter find(TypeDescriptor sourceType, TypeDescriptor targetType) { // Search the full type hierarchy List> sourceCandidates = getClassHierarchy(sourceType.getType()); @@ -542,6 +550,7 @@ public class GenericConversionService implements ConfigurableConversionService { return null; } + @Nullable private GenericConverter getRegisteredConverter(TypeDescriptor sourceType, TypeDescriptor targetType, ConvertiblePair convertiblePair) { @@ -647,6 +656,7 @@ public class GenericConversionService implements ConfigurableConversionService { this.converters.addFirst(converter); } + @Nullable public GenericConverter getConverter(TypeDescriptor sourceType, TypeDescriptor targetType) { for (GenericConverter converter : this.converters) { if (!(converter instanceof ConditionalGenericConverter) || diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/IdToEntityConverter.java b/spring-core/src/main/java/org/springframework/core/convert/support/IdToEntityConverter.java index cd130bc319..0f37a38379 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/IdToEntityConverter.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/IdToEntityConverter.java @@ -24,6 +24,7 @@ import java.util.Set; import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.TypeDescriptor; import org.springframework.core.convert.converter.ConditionalGenericConverter; +import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.util.ReflectionUtils; @@ -71,7 +72,7 @@ final class IdToEntityConverter implements ConditionalGenericConverter { return ReflectionUtils.invokeMethod(finder, source, id); } - + @Nullable private Method getFinder(Class entityClass) { String finderMethod = "find" + getEntityName(entityClass); Method[] methods; diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/package-info.java b/spring-core/src/main/java/org/springframework/core/convert/support/package-info.java index 2a23abd9f0..954c82f068 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/package-info.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/package-info.java @@ -1,4 +1,7 @@ /** * Default implementation of the type conversion system. */ +@NonNullApi package org.springframework.core.convert.support; + +import org.springframework.lang.NonNullApi; diff --git a/spring-core/src/main/java/org/springframework/core/env/AbstractPropertyResolver.java b/spring-core/src/main/java/org/springframework/core/env/AbstractPropertyResolver.java index 32991f85c5..4521011e18 100644 --- a/spring-core/src/main/java/org/springframework/core/env/AbstractPropertyResolver.java +++ b/spring-core/src/main/java/org/springframework/core/env/AbstractPropertyResolver.java @@ -25,6 +25,7 @@ import org.apache.commons.logging.LogFactory; import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.support.ConfigurableConversionService; import org.springframework.core.convert.support.DefaultConversionService; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.PropertyPlaceholderHelper; @@ -267,6 +268,7 @@ public abstract class AbstractPropertyResolver implements ConfigurablePropertyRe * @param key the property name to resolve * @return the property value or {@code null} if none found */ + @Nullable protected abstract String getPropertyAsRawString(String key); } diff --git a/spring-core/src/main/java/org/springframework/core/env/CommandLineArgs.java b/spring-core/src/main/java/org/springframework/core/env/CommandLineArgs.java index 951f1cefb8..11ee00a3da 100644 --- a/spring-core/src/main/java/org/springframework/core/env/CommandLineArgs.java +++ b/spring-core/src/main/java/org/springframework/core/env/CommandLineArgs.java @@ -23,6 +23,8 @@ import java.util.List; import java.util.Map; import java.util.Set; +import org.springframework.lang.Nullable; + /** * A simple representation of command line arguments, broken into "option arguments" and * "non-option arguments". @@ -42,7 +44,7 @@ class CommandLineArgs { * The given value may be {@code null}, indicating that the option was specified * without an associated value (e.g. "--foo" vs. "--foo=bar"). */ - public void addOptionArg(String optionName, String optionValue) { + public void addOptionArg(String optionName, @Nullable String optionValue) { if (!this.optionArgs.containsKey(optionName)) { this.optionArgs.put(optionName, new ArrayList<>()); } @@ -70,6 +72,7 @@ class CommandLineArgs { * that the option was not present; empty list signifies that no values were associated * with this option. */ + @Nullable public List getOptionValues(String optionName) { return this.optionArgs.get(optionName); } diff --git a/spring-core/src/main/java/org/springframework/core/env/CommandLinePropertySource.java b/spring-core/src/main/java/org/springframework/core/env/CommandLinePropertySource.java index 1a47e0ebb5..f4905331da 100644 --- a/spring-core/src/main/java/org/springframework/core/env/CommandLinePropertySource.java +++ b/spring-core/src/main/java/org/springframework/core/env/CommandLinePropertySource.java @@ -19,6 +19,7 @@ package org.springframework.core.env; import java.util.Collection; import java.util.List; +import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; /** @@ -305,6 +306,7 @@ public abstract class CommandLinePropertySource extends EnumerablePropertySou *

  • if the option is not present, return {@code null}
  • * */ + @Nullable protected abstract List getOptionValues(String name); /** diff --git a/spring-core/src/main/java/org/springframework/core/env/ConfigurablePropertyResolver.java b/spring-core/src/main/java/org/springframework/core/env/ConfigurablePropertyResolver.java index bc626d6431..b8e4ec6208 100644 --- a/spring-core/src/main/java/org/springframework/core/env/ConfigurablePropertyResolver.java +++ b/spring-core/src/main/java/org/springframework/core/env/ConfigurablePropertyResolver.java @@ -17,6 +17,7 @@ package org.springframework.core.env; import org.springframework.core.convert.support.ConfigurableConversionService; +import org.springframework.lang.Nullable; /** * Configuration interface to be implemented by most if not all {@link PropertyResolver} @@ -71,7 +72,7 @@ public interface ConfigurablePropertyResolver extends PropertyResolver { * resolver and their associated default value, or {@code null} if no such * special character should be processed as a value separator. */ - void setValueSeparator(String valueSeparator); + void setValueSeparator(@Nullable String valueSeparator); /** * Set whether to throw an exception when encountering an unresolvable placeholder diff --git a/spring-core/src/main/java/org/springframework/core/env/EnvironmentCapable.java b/spring-core/src/main/java/org/springframework/core/env/EnvironmentCapable.java index b100048721..2880a6701d 100644 --- a/spring-core/src/main/java/org/springframework/core/env/EnvironmentCapable.java +++ b/spring-core/src/main/java/org/springframework/core/env/EnvironmentCapable.java @@ -16,6 +16,8 @@ package org.springframework.core.env; +import org.springframework.lang.Nullable; + /** * Interface indicating a component that contains and exposes an {@link Environment} reference. * @@ -44,6 +46,7 @@ public interface EnvironmentCapable { * Return the {@link Environment} associated with this component * (may be {@code null} or a default environment). */ + @Nullable Environment getEnvironment(); } diff --git a/spring-core/src/main/java/org/springframework/core/env/MutablePropertySources.java b/spring-core/src/main/java/org/springframework/core/env/MutablePropertySources.java index 10976daf71..0317c739c3 100644 --- a/spring-core/src/main/java/org/springframework/core/env/MutablePropertySources.java +++ b/spring-core/src/main/java/org/springframework/core/env/MutablePropertySources.java @@ -23,6 +23,7 @@ import java.util.concurrent.CopyOnWriteArrayList; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; /** @@ -154,6 +155,7 @@ public class MutablePropertySources implements PropertySources { * Remove and return the property source with the given name, {@code null} if not found. * @param name the name of the property source to find and remove */ + @Nullable public PropertySource remove(String name) { if (logger.isDebugEnabled()) { logger.debug(String.format("Removing [%s] PropertySource", name)); diff --git a/spring-core/src/main/java/org/springframework/core/env/PropertyResolver.java b/spring-core/src/main/java/org/springframework/core/env/PropertyResolver.java index af8278c207..8526ba90b3 100644 --- a/spring-core/src/main/java/org/springframework/core/env/PropertyResolver.java +++ b/spring-core/src/main/java/org/springframework/core/env/PropertyResolver.java @@ -16,6 +16,8 @@ package org.springframework.core.env; +import org.springframework.lang.Nullable; + /** * Interface for resolving properties against any underlying source. * @@ -41,6 +43,7 @@ public interface PropertyResolver { * @see #getProperty(String, Class) * @see #getRequiredProperty(String) */ + @Nullable String getProperty(String key); /** @@ -60,6 +63,7 @@ public interface PropertyResolver { * @param targetType the expected type of the property value * @see #getRequiredProperty(String, Class) */ + @Nullable T getProperty(String key, Class targetType); /** diff --git a/spring-core/src/main/java/org/springframework/core/env/PropertySource.java b/spring-core/src/main/java/org/springframework/core/env/PropertySource.java index 4d4f4ee86c..c394fb9d89 100644 --- a/spring-core/src/main/java/org/springframework/core/env/PropertySource.java +++ b/spring-core/src/main/java/org/springframework/core/env/PropertySource.java @@ -19,6 +19,7 @@ package org.springframework.core.env; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; @@ -117,6 +118,7 @@ public abstract class PropertySource { * @param name the property to find * @see PropertyResolver#getRequiredProperty(String) */ + @Nullable public abstract Object getProperty(String name); diff --git a/spring-core/src/main/java/org/springframework/core/env/PropertySources.java b/spring-core/src/main/java/org/springframework/core/env/PropertySources.java index 90f99594a6..b4b0d7432e 100644 --- a/spring-core/src/main/java/org/springframework/core/env/PropertySources.java +++ b/spring-core/src/main/java/org/springframework/core/env/PropertySources.java @@ -16,6 +16,8 @@ package org.springframework.core.env; +import org.springframework.lang.Nullable; + /** * Holder containing one or more {@link PropertySource} objects. * @@ -34,6 +36,7 @@ public interface PropertySources extends Iterable> { * Return the property source with the given name, {@code null} if not found. * @param name the {@linkplain PropertySource#getName() name of the property source} to find */ + @Nullable PropertySource get(String name); } diff --git a/spring-core/src/main/java/org/springframework/core/env/PropertySourcesPropertyResolver.java b/spring-core/src/main/java/org/springframework/core/env/PropertySourcesPropertyResolver.java index c5f9073126..424b2be498 100644 --- a/spring-core/src/main/java/org/springframework/core/env/PropertySourcesPropertyResolver.java +++ b/spring-core/src/main/java/org/springframework/core/env/PropertySourcesPropertyResolver.java @@ -16,6 +16,8 @@ package org.springframework.core.env; +import org.springframework.lang.Nullable; + /** * {@link PropertyResolver} implementation that resolves property values against * an underlying set of {@link PropertySources}. @@ -68,6 +70,7 @@ public class PropertySourcesPropertyResolver extends AbstractPropertyResolver { return getProperty(key, String.class, false); } + @Nullable protected T getProperty(String key, Class targetValueType, boolean resolveNestedPlaceholders) { if (this.propertySources != null) { for (PropertySource propertySource : this.propertySources) { diff --git a/spring-core/src/main/java/org/springframework/core/env/SystemEnvironmentPropertySource.java b/spring-core/src/main/java/org/springframework/core/env/SystemEnvironmentPropertySource.java index d72a822e12..b6237dabcc 100644 --- a/spring-core/src/main/java/org/springframework/core/env/SystemEnvironmentPropertySource.java +++ b/spring-core/src/main/java/org/springframework/core/env/SystemEnvironmentPropertySource.java @@ -18,6 +18,7 @@ package org.springframework.core.env; import java.util.Map; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -117,6 +118,7 @@ public class SystemEnvironmentPropertySource extends MapPropertySource { return name; } + @Nullable private String checkPropertyName(String name) { // Check name as-is if (containsKey(name)) { diff --git a/spring-core/src/main/java/org/springframework/core/env/package-info.java b/spring-core/src/main/java/org/springframework/core/env/package-info.java index b454a6c65c..5939ffabba 100644 --- a/spring-core/src/main/java/org/springframework/core/env/package-info.java +++ b/spring-core/src/main/java/org/springframework/core/env/package-info.java @@ -2,4 +2,7 @@ * Spring's environment abstraction consisting of bean definition * profile and hierarchical property source support. */ +@NonNullApi package org.springframework.core.env; + +import org.springframework.lang.NonNullApi; diff --git a/spring-core/src/main/java/org/springframework/core/io/ClassPathResource.java b/spring-core/src/main/java/org/springframework/core/io/ClassPathResource.java index 10a379700e..0496c84bd7 100644 --- a/spring-core/src/main/java/org/springframework/core/io/ClassPathResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/ClassPathResource.java @@ -21,6 +21,7 @@ import java.io.IOException; import java.io.InputStream; import java.net.URL; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.ObjectUtils; @@ -72,7 +73,7 @@ public class ClassPathResource extends AbstractFileResolvingResource { * or {@code null} for the thread context class loader * @see ClassLoader#getResourceAsStream(String) */ - public ClassPathResource(String path, ClassLoader classLoader) { + public ClassPathResource(String path, @Nullable ClassLoader classLoader) { Assert.notNull(path, "Path must not be null"); String pathToUse = StringUtils.cleanPath(path); if (pathToUse.startsWith("/")) { @@ -90,7 +91,7 @@ public class ClassPathResource extends AbstractFileResolvingResource { * @param clazz the class to load resources with * @see java.lang.Class#getResourceAsStream */ - public ClassPathResource(String path, Class clazz) { + public ClassPathResource(String path, @Nullable Class clazz) { Assert.notNull(path, "Path must not be null"); this.path = StringUtils.cleanPath(path); this.clazz = clazz; @@ -103,7 +104,7 @@ public class ClassPathResource extends AbstractFileResolvingResource { * @param classLoader the class loader to load the resource with, if any * @param clazz the class to load resources with, if any */ - protected ClassPathResource(String path, ClassLoader classLoader, Class clazz) { + protected ClassPathResource(String path, @Nullable ClassLoader classLoader, @Nullable Class clazz) { this.path = StringUtils.cleanPath(path); this.classLoader = classLoader; this.clazz = clazz; @@ -139,6 +140,7 @@ public class ClassPathResource extends AbstractFileResolvingResource { * Resolves a URL for the underlying class path resource. * @return the resolved URL, or {@code null} if not resolvable */ + @Nullable protected URL resolveURL() { if (this.clazz != null) { return this.clazz.getResource(this.path); diff --git a/spring-core/src/main/java/org/springframework/core/io/DefaultResourceLoader.java b/spring-core/src/main/java/org/springframework/core/io/DefaultResourceLoader.java index 390ed21bdc..857dd37971 100644 --- a/spring-core/src/main/java/org/springframework/core/io/DefaultResourceLoader.java +++ b/spring-core/src/main/java/org/springframework/core/io/DefaultResourceLoader.java @@ -24,6 +24,7 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.StringUtils; @@ -67,7 +68,7 @@ public class DefaultResourceLoader implements ResourceLoader { * @param classLoader the ClassLoader to load class path resources with, or {@code null} * for using the thread context class loader at the time of actual resource access */ - public DefaultResourceLoader(ClassLoader classLoader) { + public DefaultResourceLoader(@Nullable ClassLoader classLoader) { this.classLoader = classLoader; } @@ -78,7 +79,7 @@ public class DefaultResourceLoader implements ResourceLoader { *

    The default is that ClassLoader access will happen using the thread context * class loader at the time of this ResourceLoader's initialization. */ - public void setClassLoader(ClassLoader classLoader) { + public void setClassLoader(@Nullable ClassLoader classLoader) { this.classLoader = classLoader; } diff --git a/spring-core/src/main/java/org/springframework/core/io/ProtocolResolver.java b/spring-core/src/main/java/org/springframework/core/io/ProtocolResolver.java index 6d808c37c3..1dc20d6ef6 100644 --- a/spring-core/src/main/java/org/springframework/core/io/ProtocolResolver.java +++ b/spring-core/src/main/java/org/springframework/core/io/ProtocolResolver.java @@ -16,6 +16,8 @@ package org.springframework.core.io; +import org.springframework.lang.Nullable; + /** * A resolution strategy for protocol-specific resource handles. * @@ -38,6 +40,7 @@ public interface ProtocolResolver { * @return a corresponding {@code Resource} handle if the given location * matches this resolver's protocol, or {@code null} otherwise */ + @Nullable Resource resolve(String location, ResourceLoader resourceLoader); } diff --git a/spring-core/src/main/java/org/springframework/core/io/Resource.java b/spring-core/src/main/java/org/springframework/core/io/Resource.java index c26c27754c..40e7f0c13c 100644 --- a/spring-core/src/main/java/org/springframework/core/io/Resource.java +++ b/spring-core/src/main/java/org/springframework/core/io/Resource.java @@ -24,6 +24,8 @@ import java.net.URL; import java.nio.channels.Channels; import java.nio.channels.ReadableByteChannel; +import org.springframework.lang.Nullable; + /** * Interface for a resource descriptor that abstracts from the actual * type of underlying resource, such as a file or class path resource. @@ -159,6 +161,7 @@ public interface Resource extends InputStreamSource { *

    Returns {@code null} if this type of resource does not * have a filename. */ + @Nullable String getFilename(); /** diff --git a/spring-core/src/main/java/org/springframework/core/io/ResourceEditor.java b/spring-core/src/main/java/org/springframework/core/io/ResourceEditor.java index d963b976f9..5e5bf190a0 100644 --- a/spring-core/src/main/java/org/springframework/core/io/ResourceEditor.java +++ b/spring-core/src/main/java/org/springframework/core/io/ResourceEditor.java @@ -21,6 +21,7 @@ import java.io.IOException; import org.springframework.core.env.PropertyResolver; import org.springframework.core.env.StandardEnvironment; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -120,6 +121,7 @@ public class ResourceEditor extends PropertyEditorSupport { @Override + @Nullable public String getAsText() { Resource value = (Resource) getValue(); try { diff --git a/spring-core/src/main/java/org/springframework/core/io/ResourceLoader.java b/spring-core/src/main/java/org/springframework/core/io/ResourceLoader.java index 1ca7e584c9..01254a4825 100644 --- a/spring-core/src/main/java/org/springframework/core/io/ResourceLoader.java +++ b/spring-core/src/main/java/org/springframework/core/io/ResourceLoader.java @@ -16,6 +16,7 @@ package org.springframework.core.io; +import org.springframework.lang.Nullable; import org.springframework.util.ResourceUtils; /** @@ -74,6 +75,7 @@ public interface ResourceLoader { * ClassLoader isn't accessible) * @see org.springframework.util.ClassUtils#getDefaultClassLoader() */ + @Nullable ClassLoader getClassLoader(); } diff --git a/spring-core/src/main/java/org/springframework/core/io/buffer/package-info.java b/spring-core/src/main/java/org/springframework/core/io/buffer/package-info.java index 92b55d84ae..c49eadf6f4 100644 --- a/spring-core/src/main/java/org/springframework/core/io/buffer/package-info.java +++ b/spring-core/src/main/java/org/springframework/core/io/buffer/package-info.java @@ -1,4 +1,7 @@ /** * Generic abstraction for working with byte buffer implementations. */ +@NonNullApi package org.springframework.core.io.buffer; + +import org.springframework.lang.NonNullApi; diff --git a/spring-core/src/main/java/org/springframework/core/io/package-info.java b/spring-core/src/main/java/org/springframework/core/io/package-info.java index 2d3136a771..02a8633e5a 100644 --- a/spring-core/src/main/java/org/springframework/core/io/package-info.java +++ b/spring-core/src/main/java/org/springframework/core/io/package-info.java @@ -1,4 +1,7 @@ /** * Generic abstraction for (file-based) resources, used throughout the framework. */ +@NonNullApi package org.springframework.core.io; + +import org.springframework.lang.NonNullApi; diff --git a/spring-core/src/main/java/org/springframework/core/io/support/EncodedResource.java b/spring-core/src/main/java/org/springframework/core/io/support/EncodedResource.java index 7f1c730517..0ba324b4ca 100644 --- a/spring-core/src/main/java/org/springframework/core/io/support/EncodedResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/support/EncodedResource.java @@ -24,6 +24,7 @@ import java.nio.charset.Charset; import org.springframework.core.io.InputStreamSource; import org.springframework.core.io.Resource; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; @@ -99,6 +100,7 @@ public class EncodedResource implements InputStreamSource { * Return the encoding to use for reading from the {@linkplain #getResource() resource}, * or {@code null} if none specified. */ + @Nullable public final String getEncoding() { return this.encoding; } @@ -107,6 +109,7 @@ public class EncodedResource implements InputStreamSource { * Return the {@code Charset} to use for reading from the {@linkplain #getResource() resource}, * or {@code null} if none specified. */ + @Nullable public final Charset getCharset() { return this.charset; } diff --git a/spring-core/src/main/java/org/springframework/core/io/support/LocalizedResourceHelper.java b/spring-core/src/main/java/org/springframework/core/io/support/LocalizedResourceHelper.java index 57f2645a98..994c81d0a2 100644 --- a/spring-core/src/main/java/org/springframework/core/io/support/LocalizedResourceHelper.java +++ b/spring-core/src/main/java/org/springframework/core/io/support/LocalizedResourceHelper.java @@ -21,6 +21,7 @@ import java.util.Locale; import org.springframework.core.io.DefaultResourceLoader; import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceLoader; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -86,7 +87,7 @@ public class LocalizedResourceHelper { * @return the most specific localized resource found * @see java.util.ResourceBundle */ - public Resource findLocalizedResource(String name, String extension, Locale locale) { + public Resource findLocalizedResource(String name, String extension, @Nullable Locale locale) { Assert.notNull(name, "Name must not be null"); Assert.notNull(extension, "Extension must not be null"); diff --git a/spring-core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java b/spring-core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java index 4e5da8b677..5ee20408d6 100644 --- a/spring-core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java +++ b/spring-core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java @@ -44,6 +44,7 @@ import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceLoader; import org.springframework.core.io.UrlResource; import org.springframework.core.io.VfsResource; +import org.springframework.lang.Nullable; import org.springframework.util.AntPathMatcher; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; @@ -229,7 +230,7 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol * at the time of actual resource access * @see org.springframework.core.io.DefaultResourceLoader */ - public PathMatchingResourcePatternResolver(ClassLoader classLoader) { + public PathMatchingResourcePatternResolver(@Nullable ClassLoader classLoader) { this.resourceLoader = new DefaultResourceLoader(classLoader); } @@ -817,6 +818,7 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol } @Override + @Nullable public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { String methodName = method.getName(); if (Object.class == method.getDeclaringClass()) { diff --git a/spring-core/src/main/java/org/springframework/core/io/support/PropertiesLoaderUtils.java b/spring-core/src/main/java/org/springframework/core/io/support/PropertiesLoaderUtils.java index a9fa5d6db5..86ffd881af 100644 --- a/spring-core/src/main/java/org/springframework/core/io/support/PropertiesLoaderUtils.java +++ b/spring-core/src/main/java/org/springframework/core/io/support/PropertiesLoaderUtils.java @@ -25,6 +25,7 @@ import java.util.Enumeration; import java.util.Properties; import org.springframework.core.io.Resource; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.DefaultPropertiesPersister; @@ -168,7 +169,7 @@ public abstract class PropertiesLoaderUtils { * @return the populated Properties instance * @throws IOException if loading failed */ - public static Properties loadAllProperties(String resourceName, ClassLoader classLoader) throws IOException { + public static Properties loadAllProperties(String resourceName, @Nullable ClassLoader classLoader) throws IOException { Assert.notNull(resourceName, "Resource name must not be null"); ClassLoader classLoaderToUse = classLoader; if (classLoaderToUse == null) { diff --git a/spring-core/src/main/java/org/springframework/core/io/support/ResourcePatternUtils.java b/spring-core/src/main/java/org/springframework/core/io/support/ResourcePatternUtils.java index e9721a9517..e9665b133e 100644 --- a/spring-core/src/main/java/org/springframework/core/io/support/ResourcePatternUtils.java +++ b/spring-core/src/main/java/org/springframework/core/io/support/ResourcePatternUtils.java @@ -17,6 +17,7 @@ package org.springframework.core.io.support; import org.springframework.core.io.ResourceLoader; +import org.springframework.lang.Nullable; import org.springframework.util.ResourceUtils; /** @@ -57,7 +58,7 @@ public abstract class ResourcePatternUtils { * @return the ResourcePatternResolver * @see PathMatchingResourcePatternResolver */ - public static ResourcePatternResolver getResourcePatternResolver(ResourceLoader resourceLoader) { + public static ResourcePatternResolver getResourcePatternResolver(@Nullable ResourceLoader resourceLoader) { if (resourceLoader instanceof ResourcePatternResolver) { return (ResourcePatternResolver) resourceLoader; } diff --git a/spring-core/src/main/java/org/springframework/core/io/support/SpringFactoriesLoader.java b/spring-core/src/main/java/org/springframework/core/io/support/SpringFactoriesLoader.java index a3b80bfb32..c5e69cdc62 100644 --- a/spring-core/src/main/java/org/springframework/core/io/support/SpringFactoriesLoader.java +++ b/spring-core/src/main/java/org/springframework/core/io/support/SpringFactoriesLoader.java @@ -31,6 +31,7 @@ import org.apache.commons.logging.LogFactory; import org.springframework.core.annotation.AnnotationAwareOrderComparator; import org.springframework.core.io.UrlResource; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.ConcurrentReferenceHashMap; @@ -85,7 +86,7 @@ public abstract class SpringFactoriesLoader { * @throws IllegalArgumentException if any factory implementation class cannot * be loaded or if an error occurs while instantiating any factory */ - public static List loadFactories(Class factoryClass, ClassLoader classLoader) { + public static List loadFactories(Class factoryClass, @Nullable ClassLoader classLoader) { Assert.notNull(factoryClass, "'factoryClass' must not be null"); ClassLoader classLoaderToUse = classLoader; if (classLoaderToUse == null) { @@ -113,7 +114,7 @@ public abstract class SpringFactoriesLoader { * @see #loadFactories * @throws IllegalArgumentException if an error occurs while loading factory names */ - public static List loadFactoryNames(Class factoryClass, ClassLoader classLoader) { + public static List loadFactoryNames(Class factoryClass, @Nullable ClassLoader classLoader) { String factoryClassName = factoryClass.getName(); return loadSpringFactories(classLoader).getOrDefault(factoryClassName, Collections.emptyList()); } diff --git a/spring-core/src/main/java/org/springframework/core/io/support/package-info.java b/spring-core/src/main/java/org/springframework/core/io/support/package-info.java index ab1ad3be57..de525d5ed6 100644 --- a/spring-core/src/main/java/org/springframework/core/io/support/package-info.java +++ b/spring-core/src/main/java/org/springframework/core/io/support/package-info.java @@ -2,4 +2,7 @@ * Support classes for Spring's resource abstraction. * Includes a ResourcePatternResolver mechanism. */ +@NonNullApi package org.springframework.core.io.support; + +import org.springframework.lang.NonNullApi; diff --git a/spring-core/src/main/java/org/springframework/core/package-info.java b/spring-core/src/main/java/org/springframework/core/package-info.java index 01cf7600ac..f1d5c2c70b 100644 --- a/spring-core/src/main/java/org/springframework/core/package-info.java +++ b/spring-core/src/main/java/org/springframework/core/package-info.java @@ -2,4 +2,7 @@ * Provides basic classes for exception handling and version detection, * and other core helpers that are not specific to any part of the framework. */ +@NonNullApi package org.springframework.core; + +import org.springframework.lang.NonNullApi; diff --git a/spring-core/src/main/java/org/springframework/core/serializer/package-info.java b/spring-core/src/main/java/org/springframework/core/serializer/package-info.java index cbfc8d45c8..e577036602 100644 --- a/spring-core/src/main/java/org/springframework/core/serializer/package-info.java +++ b/spring-core/src/main/java/org/springframework/core/serializer/package-info.java @@ -3,4 +3,7 @@ * Provides an abstraction over various serialization techniques. * Includes exceptions for serialization and deserialization failures. */ +@NonNullApi package org.springframework.core.serializer; + +import org.springframework.lang.NonNullApi; diff --git a/spring-core/src/main/java/org/springframework/core/serializer/support/package-info.java b/spring-core/src/main/java/org/springframework/core/serializer/support/package-info.java index 8d1a4be73a..bdc50c04c3 100644 --- a/spring-core/src/main/java/org/springframework/core/serializer/support/package-info.java +++ b/spring-core/src/main/java/org/springframework/core/serializer/support/package-info.java @@ -2,4 +2,7 @@ * Support classes for Spring's serializer abstraction. * Includes adapters to the Converter SPI. */ +@NonNullApi package org.springframework.core.serializer.support; + +import org.springframework.lang.NonNullApi; diff --git a/spring-core/src/main/java/org/springframework/core/style/ValueStyler.java b/spring-core/src/main/java/org/springframework/core/style/ValueStyler.java index 731fb3aed3..aa8e51ef57 100644 --- a/spring-core/src/main/java/org/springframework/core/style/ValueStyler.java +++ b/spring-core/src/main/java/org/springframework/core/style/ValueStyler.java @@ -16,6 +16,8 @@ package org.springframework.core.style; +import org.springframework.lang.Nullable; + /** * Strategy that encapsulates value String styling algorithms * according to Spring conventions. @@ -30,6 +32,6 @@ public interface ValueStyler { * @param value the Object value to style * @return the styled String */ - String style(Object value); + String style(@Nullable Object value); } diff --git a/spring-core/src/main/java/org/springframework/core/style/package-info.java b/spring-core/src/main/java/org/springframework/core/style/package-info.java index 4b10242189..9c7abc49ef 100644 --- a/spring-core/src/main/java/org/springframework/core/style/package-info.java +++ b/spring-core/src/main/java/org/springframework/core/style/package-info.java @@ -1,4 +1,7 @@ /** * Support for styling values as Strings, with ToStringCreator as central class. */ +@NonNullApi package org.springframework.core.style; + +import org.springframework.lang.NonNullApi; diff --git a/spring-core/src/main/java/org/springframework/core/task/SimpleAsyncTaskExecutor.java b/spring-core/src/main/java/org/springframework/core/task/SimpleAsyncTaskExecutor.java index 8d392835a9..5fecad586a 100644 --- a/spring-core/src/main/java/org/springframework/core/task/SimpleAsyncTaskExecutor.java +++ b/spring-core/src/main/java/org/springframework/core/task/SimpleAsyncTaskExecutor.java @@ -22,6 +22,7 @@ import java.util.concurrent.Future; import java.util.concurrent.FutureTask; import java.util.concurrent.ThreadFactory; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ConcurrencyThrottleSupport; import org.springframework.util.CustomizableThreadCreator; @@ -107,6 +108,7 @@ public class SimpleAsyncTaskExecutor extends CustomizableThreadCreator implement /** * Return the external factory to use for creating new Threads, if any. */ + @Nullable public final ThreadFactory getThreadFactory() { return this.threadFactory; } diff --git a/spring-core/src/main/java/org/springframework/core/task/package-info.java b/spring-core/src/main/java/org/springframework/core/task/package-info.java index ae0ec87905..599d6161f6 100644 --- a/spring-core/src/main/java/org/springframework/core/task/package-info.java +++ b/spring-core/src/main/java/org/springframework/core/task/package-info.java @@ -2,4 +2,7 @@ * This package defines Spring's core TaskExecutor abstraction, * and provides SyncTaskExecutor and SimpleAsyncTaskExecutor implementations. */ +@NonNullApi package org.springframework.core.task; + +import org.springframework.lang.NonNullApi; diff --git a/spring-core/src/main/java/org/springframework/core/task/support/TaskExecutorAdapter.java b/spring-core/src/main/java/org/springframework/core/task/support/TaskExecutorAdapter.java index 2811f7f924..72576a02e6 100644 --- a/spring-core/src/main/java/org/springframework/core/task/support/TaskExecutorAdapter.java +++ b/spring-core/src/main/java/org/springframework/core/task/support/TaskExecutorAdapter.java @@ -26,6 +26,7 @@ import java.util.concurrent.RejectedExecutionException; import org.springframework.core.task.AsyncListenableTaskExecutor; import org.springframework.core.task.TaskDecorator; import org.springframework.core.task.TaskRejectedException; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.concurrent.ListenableFuture; import org.springframework.util.concurrent.ListenableFutureTask; @@ -167,7 +168,7 @@ public class TaskExecutorAdapter implements AsyncListenableTaskExecutor { * @throws RejectedExecutionException if the given runnable cannot be accepted * @since 4.3 */ - protected void doExecute(Executor concurrentExecutor, TaskDecorator taskDecorator, Runnable runnable) + protected void doExecute(Executor concurrentExecutor, @Nullable TaskDecorator taskDecorator, Runnable runnable) throws RejectedExecutionException{ concurrentExecutor.execute(taskDecorator != null ? taskDecorator.decorate(runnable) : runnable); diff --git a/spring-core/src/main/java/org/springframework/core/task/support/package-info.java b/spring-core/src/main/java/org/springframework/core/task/support/package-info.java index 6a940a6c47..4f789307fe 100644 --- a/spring-core/src/main/java/org/springframework/core/task/support/package-info.java +++ b/spring-core/src/main/java/org/springframework/core/task/support/package-info.java @@ -2,4 +2,7 @@ * Support classes for Spring's TaskExecutor abstraction. * Includes an adapter for the standard ExecutorService interface. */ +@NonNullApi package org.springframework.core.task.support; + +import org.springframework.lang.NonNullApi; diff --git a/spring-core/src/main/java/org/springframework/core/type/AnnotatedTypeMetadata.java b/spring-core/src/main/java/org/springframework/core/type/AnnotatedTypeMetadata.java index 29541e8bb1..9a989563d6 100644 --- a/spring-core/src/main/java/org/springframework/core/type/AnnotatedTypeMetadata.java +++ b/spring-core/src/main/java/org/springframework/core/type/AnnotatedTypeMetadata.java @@ -18,6 +18,7 @@ package org.springframework.core.type; import java.util.Map; +import org.springframework.lang.Nullable; import org.springframework.util.MultiValueMap; /** @@ -58,6 +59,7 @@ public interface AnnotatedTypeMetadata { * and the defined attribute value as Map value. This return value will be * {@code null} if no matching annotation is defined. */ + @Nullable Map getAnnotationAttributes(String annotationName); /** @@ -73,6 +75,7 @@ public interface AnnotatedTypeMetadata { * and the defined attribute value as Map value. This return value will be * {@code null} if no matching annotation is defined. */ + @Nullable Map getAnnotationAttributes(String annotationName, boolean classValuesAsString); /** @@ -86,6 +89,7 @@ public interface AnnotatedTypeMetadata { * be {@code null} if no matching annotation is defined. * @see #getAllAnnotationAttributes(String, boolean) */ + @Nullable MultiValueMap getAllAnnotationAttributes(String annotationName); /** @@ -100,6 +104,7 @@ public interface AnnotatedTypeMetadata { * be {@code null} if no matching annotation is defined. * @see #getAllAnnotationAttributes(String) */ + @Nullable MultiValueMap getAllAnnotationAttributes(String annotationName, boolean classValuesAsString); } diff --git a/spring-core/src/main/java/org/springframework/core/type/ClassMetadata.java b/spring-core/src/main/java/org/springframework/core/type/ClassMetadata.java index d664198e7d..627be0f472 100644 --- a/spring-core/src/main/java/org/springframework/core/type/ClassMetadata.java +++ b/spring-core/src/main/java/org/springframework/core/type/ClassMetadata.java @@ -16,6 +16,8 @@ package org.springframework.core.type; +import org.springframework.lang.Nullable; + /** * Interface that defines abstract metadata of a specific class, * in a form that does not require that class to be loaded yet. @@ -81,6 +83,7 @@ public interface ClassMetadata { * Return the name of the enclosing class of the underlying class, * or {@code null} if the underlying class is a top-level class. */ + @Nullable String getEnclosingClassName(); /** @@ -92,6 +95,7 @@ public interface ClassMetadata { * Return the name of the super class of the underlying class, * or {@code null} if there is no super class defined. */ + @Nullable String getSuperClassName(); /** diff --git a/spring-core/src/main/java/org/springframework/core/type/classreading/AnnotationReadingVisitorUtils.java b/spring-core/src/main/java/org/springframework/core/type/classreading/AnnotationReadingVisitorUtils.java index 079d32eab1..afcd4b5682 100644 --- a/spring-core/src/main/java/org/springframework/core/type/classreading/AnnotationReadingVisitorUtils.java +++ b/spring-core/src/main/java/org/springframework/core/type/classreading/AnnotationReadingVisitorUtils.java @@ -26,6 +26,7 @@ import java.util.Set; import org.springframework.asm.Type; import org.springframework.core.annotation.AnnotationAttributes; import org.springframework.core.annotation.AnnotationUtils; +import org.springframework.lang.Nullable; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.ObjectUtils; @@ -119,6 +120,7 @@ abstract class AnnotationReadingVisitorUtils { * matching annotation is present in the {@code attributesMap} * @since 4.0.3 */ + @Nullable public static AnnotationAttributes getMergedAnnotationAttributes( LinkedMultiValueMap attributesMap, Map> metaAnnotationMap, String annotationName) { diff --git a/spring-core/src/main/java/org/springframework/core/type/classreading/package-info.java b/spring-core/src/main/java/org/springframework/core/type/classreading/package-info.java index 9c9ca0dda3..3844028908 100644 --- a/spring-core/src/main/java/org/springframework/core/type/classreading/package-info.java +++ b/spring-core/src/main/java/org/springframework/core/type/classreading/package-info.java @@ -1,4 +1,7 @@ /** * Support classes for reading annotation and class-level metadata. */ +@NonNullApi package org.springframework.core.type.classreading; + +import org.springframework.lang.NonNullApi; diff --git a/spring-core/src/main/java/org/springframework/core/type/filter/AbstractTypeHierarchyTraversingFilter.java b/spring-core/src/main/java/org/springframework/core/type/filter/AbstractTypeHierarchyTraversingFilter.java index b10db84aa6..1981eff2a6 100644 --- a/spring-core/src/main/java/org/springframework/core/type/filter/AbstractTypeHierarchyTraversingFilter.java +++ b/spring-core/src/main/java/org/springframework/core/type/filter/AbstractTypeHierarchyTraversingFilter.java @@ -24,6 +24,7 @@ import org.apache.commons.logging.LogFactory; import org.springframework.core.type.ClassMetadata; import org.springframework.core.type.classreading.MetadataReader; import org.springframework.core.type.classreading.MetadataReaderFactory; +import org.springframework.lang.Nullable; /** * Type filter that is aware of traversing over hierarchy. @@ -140,6 +141,7 @@ public abstract class AbstractTypeHierarchyTraversingFilter implements TypeFilte /** * Override this to match on super type name. */ + @Nullable protected Boolean matchSuperClass(String superClassName) { return null; } @@ -147,6 +149,7 @@ public abstract class AbstractTypeHierarchyTraversingFilter implements TypeFilte /** * Override this to match on interface type name. */ + @Nullable protected Boolean matchInterface(String interfaceName) { return null; } diff --git a/spring-core/src/main/java/org/springframework/core/type/filter/AnnotationTypeFilter.java b/spring-core/src/main/java/org/springframework/core/type/filter/AnnotationTypeFilter.java index 3e31aca161..74fd6fab2a 100644 --- a/spring-core/src/main/java/org/springframework/core/type/filter/AnnotationTypeFilter.java +++ b/spring-core/src/main/java/org/springframework/core/type/filter/AnnotationTypeFilter.java @@ -22,6 +22,7 @@ import java.lang.annotation.Inherited; import org.springframework.core.annotation.AnnotationUtils; import org.springframework.core.type.AnnotationMetadata; import org.springframework.core.type.classreading.MetadataReader; +import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; /** @@ -102,6 +103,7 @@ public class AnnotationTypeFilter extends AbstractTypeHierarchyTraversingFilter return hasAnnotation(interfaceName); } + @Nullable protected Boolean hasAnnotation(String typeName) { if (Object.class.getName().equals(typeName)) { return false; diff --git a/spring-core/src/main/java/org/springframework/core/type/filter/AssignableTypeFilter.java b/spring-core/src/main/java/org/springframework/core/type/filter/AssignableTypeFilter.java index d67056ff79..79665b8d3e 100644 --- a/spring-core/src/main/java/org/springframework/core/type/filter/AssignableTypeFilter.java +++ b/spring-core/src/main/java/org/springframework/core/type/filter/AssignableTypeFilter.java @@ -16,6 +16,7 @@ package org.springframework.core.type.filter; +import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; /** @@ -63,6 +64,7 @@ public class AssignableTypeFilter extends AbstractTypeHierarchyTraversingFilter return matchTargetType(interfaceName); } + @Nullable protected Boolean matchTargetType(String typeName) { if (this.targetType.getName().equals(typeName)) { return true; diff --git a/spring-core/src/main/java/org/springframework/core/type/filter/package-info.java b/spring-core/src/main/java/org/springframework/core/type/filter/package-info.java index 6f08effe76..4eafe49ae7 100644 --- a/spring-core/src/main/java/org/springframework/core/type/filter/package-info.java +++ b/spring-core/src/main/java/org/springframework/core/type/filter/package-info.java @@ -1,4 +1,7 @@ /** * Core support package for type filtering (e.g. for classpath scanning). */ +@NonNullApi package org.springframework.core.type.filter; + +import org.springframework.lang.NonNullApi; diff --git a/spring-core/src/main/java/org/springframework/core/type/package-info.java b/spring-core/src/main/java/org/springframework/core/type/package-info.java index 00179fb526..56b4c2ffa7 100644 --- a/spring-core/src/main/java/org/springframework/core/type/package-info.java +++ b/spring-core/src/main/java/org/springframework/core/type/package-info.java @@ -1,4 +1,7 @@ /** * Core support package for type introspection. */ +@NonNullApi package org.springframework.core.type; + +import org.springframework.lang.NonNullApi; diff --git a/spring-core/src/main/java/org/springframework/lang/NonNullApi.java b/spring-core/src/main/java/org/springframework/lang/NonNullApi.java new file mode 100644 index 0000000000..ae95ebfa13 --- /dev/null +++ b/spring-core/src/main/java/org/springframework/lang/NonNullApi.java @@ -0,0 +1,29 @@ +package org.springframework.lang; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.annotation.Nonnull; +import javax.annotation.meta.TypeQualifierDefault; + +/** + * Leverage JSR 305 meta-annotations to define that parameters and return values are + * non-nullable by default. + * + * Should be used at package level in association with {@link Nullable} parameters and + * return values level annotations. + * + * @author Sebastien Deleuze + * @since 5.0 + * @see javax.annotation.Nonnull + */ +@Documented +@Nonnull +@Target(ElementType.PACKAGE) +@TypeQualifierDefault({ElementType.METHOD, ElementType.PARAMETER}) +@Retention(RetentionPolicy.RUNTIME) +public @interface NonNullApi { +} diff --git a/spring-core/src/main/java/org/springframework/lang/Nullable.java b/spring-core/src/main/java/org/springframework/lang/Nullable.java new file mode 100644 index 0000000000..ab68cb9a77 --- /dev/null +++ b/spring-core/src/main/java/org/springframework/lang/Nullable.java @@ -0,0 +1,28 @@ +package org.springframework.lang; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.annotation.meta.TypeQualifierDefault; + +/** + * Leverage JSR 305 meta-annotations to define the annotated element could be null + * under some circumstances. + * + * Should be used at parameters and return values level in association with + * {@link NonNullApi} package level annotations. + * + * @author Sebastien Deleuze + * @since 5.0 + * @see javax.annotation.Nullable + */ +@Documented +@javax.annotation.Nullable +@Target({ElementType.METHOD, ElementType.PARAMETER}) +@TypeQualifierDefault({ElementType.METHOD, ElementType.PARAMETER}) +@Retention(RetentionPolicy.RUNTIME) +public @interface Nullable { +} diff --git a/spring-core/src/main/java/org/springframework/lang/package-info.java b/spring-core/src/main/java/org/springframework/lang/package-info.java index f9a01f9121..5fddf8838d 100644 --- a/spring-core/src/main/java/org/springframework/lang/package-info.java +++ b/spring-core/src/main/java/org/springframework/lang/package-info.java @@ -2,4 +2,6 @@ * Annotations indicating the use of core Java/JDK API beyond the API level of JDK 6 update 18. * Used descriptively within the framework codebase; validated by Animal Sniffer at build time. */ +@NonNullApi package org.springframework.lang; + diff --git a/spring-core/src/main/java/org/springframework/util/Assert.java b/spring-core/src/main/java/org/springframework/util/Assert.java index 8f60f5988d..b74b96935c 100644 --- a/spring-core/src/main/java/org/springframework/util/Assert.java +++ b/spring-core/src/main/java/org/springframework/util/Assert.java @@ -20,6 +20,8 @@ import java.util.Collection; import java.util.Map; import java.util.function.Supplier; +import org.springframework.lang.Nullable; + /** * Assertion utility class that assists in validating arguments. * @@ -148,7 +150,7 @@ public abstract class Assert { * @param message the exception message to use if the assertion fails * @throws IllegalArgumentException if the object is not {@code null} */ - public static void isNull(Object object, String message) { + public static void isNull(@Nullable Object object, String message) { if (object != null) { throw new IllegalArgumentException(message); } @@ -165,7 +167,7 @@ public abstract class Assert { * @throws IllegalArgumentException if the object is not {@code null} * @since 5.0 */ - public static void isNull(Object object, Supplier messageSupplier) { + public static void isNull(@Nullable Object object, Supplier messageSupplier) { if (object != null) { throw new IllegalArgumentException(nullSafeGet(messageSupplier)); } @@ -175,7 +177,7 @@ public abstract class Assert { * @deprecated as of 4.3.7, in favor of {@link #isNull(Object, String)} */ @Deprecated - public static void isNull(Object object) { + public static void isNull(@Nullable Object object) { isNull(object, "[Assertion failed] - the object argument must be null"); } @@ -186,7 +188,7 @@ public abstract class Assert { * @param message the exception message to use if the assertion fails * @throws IllegalArgumentException if the object is {@code null} */ - public static void notNull(Object object, String message) { + public static void notNull(@Nullable Object object, String message) { if (object == null) { throw new IllegalArgumentException(message); } @@ -203,7 +205,7 @@ public abstract class Assert { * @throws IllegalArgumentException if the object is {@code null} * @since 5.0 */ - public static void notNull(Object object, Supplier messageSupplier) { + public static void notNull(@Nullable Object object, Supplier messageSupplier) { if (object == null) { throw new IllegalArgumentException(nullSafeGet(messageSupplier)); } @@ -213,7 +215,7 @@ public abstract class Assert { * @deprecated as of 4.3.7, in favor of {@link #notNull(Object, String)} */ @Deprecated - public static void notNull(Object object) { + public static void notNull(@Nullable Object object) { notNull(object, "[Assertion failed] - this argument is required; it must not be null"); } @@ -226,7 +228,7 @@ public abstract class Assert { * @see StringUtils#hasLength * @throws IllegalArgumentException if the text is empty */ - public static void hasLength(String text, String message) { + public static void hasLength(@Nullable String text, String message) { if (!StringUtils.hasLength(text)) { throw new IllegalArgumentException(message); } @@ -245,7 +247,7 @@ public abstract class Assert { * @throws IllegalArgumentException if the text is empty * @since 5.0 */ - public static void hasLength(String text, Supplier messageSupplier) { + public static void hasLength(@Nullable String text, Supplier messageSupplier) { if (!StringUtils.hasLength(text)) { throw new IllegalArgumentException(nullSafeGet(messageSupplier)); } @@ -255,7 +257,7 @@ public abstract class Assert { * @deprecated as of 4.3.7, in favor of {@link #hasLength(String, String)} */ @Deprecated - public static void hasLength(String text) { + public static void hasLength(@Nullable String text) { hasLength(text, "[Assertion failed] - this String argument must have length; it must not be null or empty"); } @@ -269,7 +271,7 @@ public abstract class Assert { * @see StringUtils#hasText * @throws IllegalArgumentException if the text does not contain valid text content */ - public static void hasText(String text, String message) { + public static void hasText(@Nullable String text, String message) { if (!StringUtils.hasText(text)) { throw new IllegalArgumentException(message); } @@ -288,7 +290,7 @@ public abstract class Assert { * @throws IllegalArgumentException if the text does not contain valid text content * @since 5.0 */ - public static void hasText(String text, Supplier messageSupplier) { + public static void hasText(@Nullable String text, Supplier messageSupplier) { if (!StringUtils.hasText(text)) { throw new IllegalArgumentException(nullSafeGet(messageSupplier)); } @@ -298,7 +300,7 @@ public abstract class Assert { * @deprecated as of 4.3.7, in favor of {@link #hasText(String, String)} */ @Deprecated - public static void hasText(String text) { + public static void hasText(@Nullable String text) { hasText(text, "[Assertion failed] - this String argument must have text; it must not be null, empty, or blank"); } @@ -311,7 +313,7 @@ public abstract class Assert { * @param message the exception message to use if the assertion fails * @throws IllegalArgumentException if the text contains the substring */ - public static void doesNotContain(String textToSearch, String substring, String message) { + public static void doesNotContain(@Nullable String textToSearch, String substring, String message) { if (StringUtils.hasLength(textToSearch) && StringUtils.hasLength(substring) && textToSearch.contains(substring)) { throw new IllegalArgumentException(message); @@ -330,7 +332,7 @@ public abstract class Assert { * @throws IllegalArgumentException if the text contains the substring * @since 5.0 */ - public static void doesNotContain(String textToSearch, String substring, Supplier messageSupplier) { + public static void doesNotContain(@Nullable String textToSearch, String substring, Supplier messageSupplier) { if (StringUtils.hasLength(textToSearch) && StringUtils.hasLength(substring) && textToSearch.contains(substring)) { throw new IllegalArgumentException(nullSafeGet(messageSupplier)); @@ -341,7 +343,7 @@ public abstract class Assert { * @deprecated as of 4.3.7, in favor of {@link #doesNotContain(String, String, String)} */ @Deprecated - public static void doesNotContain(String textToSearch, String substring) { + public static void doesNotContain(@Nullable String textToSearch, String substring) { doesNotContain(textToSearch, substring, () -> "[Assertion failed] - this String argument must not contain the substring [" + substring + "]"); } @@ -354,7 +356,7 @@ public abstract class Assert { * @param message the exception message to use if the assertion fails * @throws IllegalArgumentException if the object array is {@code null} or contains no elements */ - public static void notEmpty(Object[] array, String message) { + public static void notEmpty(@Nullable Object[] array, String message) { if (ObjectUtils.isEmpty(array)) { throw new IllegalArgumentException(message); } @@ -372,7 +374,7 @@ public abstract class Assert { * @throws IllegalArgumentException if the object array is {@code null} or contains no elements * @since 5.0 */ - public static void notEmpty(Object[] array, Supplier messageSupplier) { + public static void notEmpty(@Nullable Object[] array, Supplier messageSupplier) { if (ObjectUtils.isEmpty(array)) { throw new IllegalArgumentException(nullSafeGet(messageSupplier)); } @@ -382,7 +384,7 @@ public abstract class Assert { * @deprecated as of 4.3.7, in favor of {@link #notEmpty(Object[], String)} */ @Deprecated - public static void notEmpty(Object[] array) { + public static void notEmpty(@Nullable Object[] array) { notEmpty(array, "[Assertion failed] - this array must not be empty: it must contain at least 1 element"); } @@ -394,7 +396,7 @@ public abstract class Assert { * @param message the exception message to use if the assertion fails * @throws IllegalArgumentException if the object array contains a {@code null} element */ - public static void noNullElements(Object[] array, String message) { + public static void noNullElements(@Nullable Object[] array, String message) { if (array != null) { for (Object element : array) { if (element == null) { @@ -416,7 +418,7 @@ public abstract class Assert { * @throws IllegalArgumentException if the object array contains a {@code null} element * @since 5.0 */ - public static void noNullElements(Object[] array, Supplier messageSupplier) { + public static void noNullElements(@Nullable Object[] array, Supplier messageSupplier) { if (array != null) { for (Object element : array) { if (element == null) { @@ -430,7 +432,7 @@ public abstract class Assert { * @deprecated as of 4.3.7, in favor of {@link #noNullElements(Object[], String)} */ @Deprecated - public static void noNullElements(Object[] array) { + public static void noNullElements(@Nullable Object[] array) { noNullElements(array, "[Assertion failed] - this array must not contain any null elements"); } @@ -443,7 +445,7 @@ public abstract class Assert { * @throws IllegalArgumentException if the collection is {@code null} or * contains no elements */ - public static void notEmpty(Collection collection, String message) { + public static void notEmpty(@Nullable Collection collection, String message) { if (CollectionUtils.isEmpty(collection)) { throw new IllegalArgumentException(message); } @@ -462,7 +464,7 @@ public abstract class Assert { * contains no elements * @since 5.0 */ - public static void notEmpty(Collection collection, Supplier messageSupplier) { + public static void notEmpty(@Nullable Collection collection, Supplier messageSupplier) { if (CollectionUtils.isEmpty(collection)) { throw new IllegalArgumentException(nullSafeGet(messageSupplier)); } @@ -472,7 +474,7 @@ public abstract class Assert { * @deprecated as of 4.3.7, in favor of {@link #notEmpty(Collection, String)} */ @Deprecated - public static void notEmpty(Collection collection) { + public static void notEmpty(@Nullable Collection collection) { notEmpty(collection, "[Assertion failed] - this collection must not be empty: it must contain at least 1 element"); } @@ -485,7 +487,7 @@ public abstract class Assert { * @param message the exception message to use if the assertion fails * @throws IllegalArgumentException if the map is {@code null} or contains no entries */ - public static void notEmpty(Map map, String message) { + public static void notEmpty(@Nullable Map map, String message) { if (CollectionUtils.isEmpty(map)) { throw new IllegalArgumentException(message); } @@ -503,7 +505,7 @@ public abstract class Assert { * @throws IllegalArgumentException if the map is {@code null} or contains no entries * @since 5.0 */ - public static void notEmpty(Map map, Supplier messageSupplier) { + public static void notEmpty(@Nullable Map map, Supplier messageSupplier) { if (CollectionUtils.isEmpty(map)) { throw new IllegalArgumentException(nullSafeGet(messageSupplier)); } @@ -513,7 +515,7 @@ public abstract class Assert { * @deprecated as of 4.3.7, in favor of {@link #notEmpty(Map, String)} */ @Deprecated - public static void notEmpty(Map map) { + public static void notEmpty(@Nullable Map map) { notEmpty(map, "[Assertion failed] - this map must not be empty; it must contain at least one entry"); } diff --git a/spring-core/src/main/java/org/springframework/util/Base64Utils.java b/spring-core/src/main/java/org/springframework/util/Base64Utils.java index 037050df74..6ea0138881 100644 --- a/spring-core/src/main/java/org/springframework/util/Base64Utils.java +++ b/spring-core/src/main/java/org/springframework/util/Base64Utils.java @@ -20,6 +20,8 @@ import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.util.Base64; +import org.springframework.lang.Nullable; + /** * A simple utility class for Base64 encoding and decoding. * @@ -42,7 +44,8 @@ public abstract class Base64Utils { * @throws IllegalStateException if Base64 encoding between byte arrays is not * supported, i.e. neither Java 8 nor Apache Commons Codec is present at runtime */ - public static byte[] encode(byte[] src) { + @Nullable + public static byte[] encode(@Nullable byte[] src) { if (src == null || src.length == 0) { return src; } @@ -56,7 +59,8 @@ public abstract class Base64Utils { * @throws IllegalStateException if Base64 encoding between byte arrays is not * supported, i.e. neither Java 8 nor Apache Commons Codec is present at runtime */ - public static byte[] decode(byte[] src) { + @Nullable + public static byte[] decode(@Nullable byte[] src) { if (src == null || src.length == 0) { return src; } @@ -72,7 +76,8 @@ public abstract class Base64Utils { * supported, i.e. neither Java 8 nor Apache Commons Codec is present at runtime * @since 4.2.4 */ - public static byte[] encodeUrlSafe(byte[] src) { + @Nullable + public static byte[] encodeUrlSafe(@Nullable byte[] src) { if (src == null || src.length == 0) { return src; } @@ -88,7 +93,8 @@ public abstract class Base64Utils { * supported, i.e. neither Java 8 nor Apache Commons Codec is present at runtime * @since 4.2.4 */ - public static byte[] decodeUrlSafe(byte[] src) { + @Nullable + public static byte[] decodeUrlSafe(@Nullable byte[] src) { if (src == null || src.length == 0) { return src; } @@ -101,7 +107,8 @@ public abstract class Base64Utils { * @return the encoded byte array as a UTF-8 String * (or {@code null} if the input was {@code null}) */ - public static String encodeToString(byte[] src) { + @Nullable + public static String encodeToString(@Nullable byte[] src) { if (src == null) { return null; } @@ -116,7 +123,8 @@ public abstract class Base64Utils { * @param src the encoded UTF-8 String (may be {@code null}) * @return the original byte array (or {@code null} if the input was {@code null}) */ - public static byte[] decodeFromString(String src) { + @Nullable + public static byte[] decodeFromString(@Nullable String src) { if (src == null) { return null; } @@ -135,7 +143,8 @@ public abstract class Base64Utils { * @throws IllegalStateException if Base64 encoding between byte arrays is not * supported, i.e. neither Java 8 nor Apache Commons Codec is present at runtime */ - public static String encodeToUrlSafeString(byte[] src) { + @Nullable + public static String encodeToUrlSafeString(@Nullable byte[] src) { return new String(encodeUrlSafe(src), DEFAULT_CHARSET); } @@ -147,7 +156,8 @@ public abstract class Base64Utils { * @throws IllegalStateException if Base64 encoding between byte arrays is not * supported, i.e. neither Java 8 nor Apache Commons Codec is present at runtime */ - public static byte[] decodeFromUrlSafeString(String src) { + @Nullable + public static byte[] decodeFromUrlSafeString(@Nullable String src) { return decodeUrlSafe(src.getBytes(DEFAULT_CHARSET)); } diff --git a/spring-core/src/main/java/org/springframework/util/ClassUtils.java b/spring-core/src/main/java/org/springframework/util/ClassUtils.java index de8124db35..9a9b0c705d 100644 --- a/spring-core/src/main/java/org/springframework/util/ClassUtils.java +++ b/spring-core/src/main/java/org/springframework/util/ClassUtils.java @@ -33,6 +33,8 @@ import java.util.LinkedHashSet; import java.util.Map; import java.util.Set; +import org.springframework.lang.Nullable; + /** * Miscellaneous class utility methods. * Mainly for internal use within the framework. @@ -154,6 +156,7 @@ public abstract class ClassUtils { * @see Thread#getContextClassLoader() * @see ClassLoader#getSystemClassLoader() */ + @Nullable public static ClassLoader getDefaultClassLoader() { ClassLoader cl = null; try { @@ -185,6 +188,7 @@ public abstract class ClassUtils { * @param classLoaderToUse the actual ClassLoader to use for the thread context * @return the original thread context ClassLoader, or {@code null} if not overridden */ + @Nullable public static ClassLoader overrideThreadContextClassLoader(ClassLoader classLoaderToUse) { Thread currentThread = Thread.currentThread(); ClassLoader threadContextClassLoader = currentThread.getContextClassLoader(); @@ -210,7 +214,7 @@ public abstract class ClassUtils { * @throws LinkageError if the class file could not be loaded * @see Class#forName(String, boolean, ClassLoader) */ - public static Class forName(String name, ClassLoader classLoader) throws ClassNotFoundException, LinkageError { + public static Class forName(String name, @Nullable ClassLoader classLoader) throws ClassNotFoundException, LinkageError { Assert.notNull(name, "Name must not be null"); Class clazz = resolvePrimitiveClassName(name); @@ -279,7 +283,7 @@ public abstract class ClassUtils { * (that is, the class could not be found or the class file could not be loaded) * @see #forName(String, ClassLoader) */ - public static Class resolveClassName(String className, ClassLoader classLoader) throws IllegalArgumentException { + public static Class resolveClassName(String className, @Nullable ClassLoader classLoader) throws IllegalArgumentException { try { return forName(className, classLoader); } @@ -302,6 +306,7 @@ public abstract class ClassUtils { * @return the primitive class, or {@code null} if the name does not denote * a primitive class or primitive array class */ + @Nullable public static Class resolvePrimitiveClassName(String name) { Class result = null; // Most class names will be quite long, considering that they @@ -322,7 +327,7 @@ public abstract class ClassUtils { * (may be {@code null}, which indicates the default class loader) * @return whether the specified class is present */ - public static boolean isPresent(String className, ClassLoader classLoader) { + public static boolean isPresent(String className, @Nullable ClassLoader classLoader) { try { forName(className, classLoader); return true; @@ -502,7 +507,7 @@ public abstract class ClassUtils { * @return the qualified name of the method * @since 4.3.4 */ - public static String getQualifiedMethodName(Method method, Class clazz) { + public static String getQualifiedMethodName(Method method, @Nullable Class clazz) { Assert.notNull(method, "Method must not be null"); return (clazz != null ? clazz : method.getDeclaringClass()).getName() + '.' + method.getName(); } @@ -568,6 +573,7 @@ public abstract class ClassUtils { * @return the constructor, or {@code null} if not found * @see Class#getConstructor */ + @Nullable public static Constructor getConstructorIfAvailable(Class clazz, Class... paramTypes) { Assert.notNull(clazz, "Class must not be null"); try { @@ -605,7 +611,7 @@ public abstract class ClassUtils { * @throws IllegalStateException if the method has not been found * @see Class#getMethod */ - public static Method getMethod(Class clazz, String methodName, Class... paramTypes) { + public static Method getMethod(Class clazz, String methodName, @Nullable Class... paramTypes) { Assert.notNull(clazz, "Class must not be null"); Assert.notNull(methodName, "Method name must not be null"); if (paramTypes != null) { @@ -649,7 +655,8 @@ public abstract class ClassUtils { * @return the method, or {@code null} if not found * @see Class#getMethod */ - public static Method getMethodIfAvailable(Class clazz, String methodName, Class... paramTypes) { + @Nullable + public static Method getMethodIfAvailable(Class clazz, String methodName, @Nullable Class... paramTypes) { Assert.notNull(clazz, "Class must not be null"); Assert.notNull(methodName, "Method name must not be null"); if (paramTypes != null) { @@ -748,7 +755,8 @@ public abstract class ClassUtils { * @return the specific target method, or the original method if the * {@code targetClass} doesn't implement it or is {@code null} */ - public static Method getMostSpecificMethod(Method method, Class targetClass) { + @Nullable + public static Method getMostSpecificMethod(Method method, @Nullable Class targetClass) { if (method != null && isOverridable(method, targetClass) && targetClass != null && targetClass != method.getDeclaringClass()) { try { @@ -816,6 +824,7 @@ public abstract class ClassUtils { * @return the static method, or {@code null} if no static method was found * @throws IllegalArgumentException if the method name is blank or the clazz is null */ + @Nullable public static Method getStaticMethod(Class clazz, String methodName, Class... args) { Assert.notNull(clazz, "Class must not be null"); Assert.notNull(methodName, "Method name must not be null"); @@ -987,7 +996,7 @@ public abstract class ClassUtils { * @see ClassLoader#getResource * @see Class#getResource */ - public static String classPackageAsResourcePath(Class clazz) { + public static String classPackageAsResourcePath(@Nullable Class clazz) { if (clazz == null) { return ""; } @@ -1009,7 +1018,7 @@ public abstract class ClassUtils { * @return a String of form "[com.foo.Bar, com.foo.Baz]" * @see java.util.AbstractCollection#toString() */ - public static String classNamesToString(Class... classes) { + public static String classNamesToString(@Nullable Class... classes) { return classNamesToString(Arrays.asList(classes)); } @@ -1022,7 +1031,7 @@ public abstract class ClassUtils { * @return a String of form "[com.foo.Bar, com.foo.Baz]" * @see java.util.AbstractCollection#toString() */ - public static String classNamesToString(Collection> classes) { + public static String classNamesToString(@Nullable Collection> classes) { if (CollectionUtils.isEmpty(classes)) { return "[]"; } @@ -1045,7 +1054,8 @@ public abstract class ClassUtils { * @return the Class array ({@code null} if the passed-in * Collection was {@code null}) */ - public static Class[] toClassArray(Collection> collection) { + @Nullable + public static Class[] toClassArray(@Nullable Collection> collection) { if (collection == null) { return null; } @@ -1083,7 +1093,7 @@ public abstract class ClassUtils { * (may be {@code null} when accepting all declared interfaces) * @return all interfaces that the given object implements as an array */ - public static Class[] getAllInterfacesForClass(Class clazz, ClassLoader classLoader) { + public static Class[] getAllInterfacesForClass(Class clazz, @Nullable ClassLoader classLoader) { Set> ifcs = getAllInterfacesForClassAsSet(clazz, classLoader); return ifcs.toArray(new Class[ifcs.size()]); } @@ -1119,7 +1129,7 @@ public abstract class ClassUtils { * (may be {@code null} when accepting all declared interfaces) * @return all interfaces that the given object implements as a Set */ - public static Set> getAllInterfacesForClassAsSet(Class clazz, ClassLoader classLoader) { + public static Set> getAllInterfacesForClassAsSet(Class clazz, @Nullable ClassLoader classLoader) { Assert.notNull(clazz, "Class must not be null"); if (clazz.isInterface() && isVisible(clazz, classLoader)) { return Collections.>singleton(clazz); @@ -1159,6 +1169,7 @@ public abstract class ClassUtils { * given classes is {@code null}, the other class will be returned. * @since 3.2.6 */ + @Nullable public static Class determineCommonAncestor(Class clazz1, Class clazz2) { if (clazz1 == null) { return clazz2; @@ -1189,7 +1200,7 @@ public abstract class ClassUtils { * @param classLoader the ClassLoader to check against (may be {@code null}, * in which case this method will always return {@code true}) */ - public static boolean isVisible(Class clazz, ClassLoader classLoader) { + public static boolean isVisible(Class clazz, @Nullable ClassLoader classLoader) { if (classLoader == null) { return true; } diff --git a/spring-core/src/main/java/org/springframework/util/CollectionUtils.java b/spring-core/src/main/java/org/springframework/util/CollectionUtils.java index a2d107af7a..c53085789f 100644 --- a/spring-core/src/main/java/org/springframework/util/CollectionUtils.java +++ b/spring-core/src/main/java/org/springframework/util/CollectionUtils.java @@ -30,6 +30,8 @@ import java.util.Map; import java.util.Properties; import java.util.Set; +import org.springframework.lang.Nullable; + /** * Miscellaneous collection utility methods. * Mainly for internal use within the framework. @@ -47,7 +49,7 @@ public abstract class CollectionUtils { * @param collection the Collection to check * @return whether the given Collection is empty */ - public static boolean isEmpty(Collection collection) { + public static boolean isEmpty(@Nullable Collection collection) { return (collection == null || collection.isEmpty()); } @@ -57,7 +59,7 @@ public abstract class CollectionUtils { * @param map the Map to check * @return whether the given Map is empty */ - public static boolean isEmpty(Map map) { + public static boolean isEmpty(@Nullable Map map) { return (map == null || map.isEmpty()); } @@ -74,7 +76,7 @@ public abstract class CollectionUtils { * @see Arrays#asList(Object[]) */ @SuppressWarnings("rawtypes") - public static List arrayToList(Object source) { + public static List arrayToList(@Nullable Object source) { return Arrays.asList(ObjectUtils.toObjectArray(source)); } @@ -84,7 +86,7 @@ public abstract class CollectionUtils { * @param collection the target Collection to merge the array into */ @SuppressWarnings("unchecked") - public static void mergeArrayIntoCollection(Object array, Collection collection) { + public static void mergeArrayIntoCollection(@Nullable Object array, Collection collection) { if (collection == null) { throw new IllegalArgumentException("Collection must not be null"); } @@ -103,7 +105,7 @@ public abstract class CollectionUtils { * @param map the target Map to merge the properties into */ @SuppressWarnings("unchecked") - public static void mergePropertiesIntoMap(Properties props, Map map) { + public static void mergePropertiesIntoMap(@Nullable Properties props, Map map) { if (map == null) { throw new IllegalArgumentException("Map must not be null"); } @@ -205,6 +207,7 @@ public abstract class CollectionUtils { * @return the first present object, or {@code null} if not found */ @SuppressWarnings("unchecked") + @Nullable public static E findFirstMatch(Collection source, Collection candidates) { if (isEmpty(source) || isEmpty(candidates)) { return null; @@ -225,6 +228,7 @@ public abstract class CollectionUtils { * or {@code null} if none or more than one such value found */ @SuppressWarnings("unchecked") + @Nullable public static T findValueOfType(Collection collection, Class type) { if (isEmpty(collection)) { return null; @@ -251,6 +255,7 @@ public abstract class CollectionUtils { * @return a value of one of the given types found if there is a clear match, * or {@code null} if none or more than one such value found */ + @Nullable public static Object findValueOfType(Collection collection, Class[] types) { if (isEmpty(collection) || ObjectUtils.isEmpty(types)) { return null; @@ -294,6 +299,7 @@ public abstract class CollectionUtils { * @return the common element type, or {@code null} if no clear * common type has been found (or the collection was empty) */ + @Nullable public static Class findCommonElementType(Collection collection) { if (isEmpty(collection)) { return null; diff --git a/spring-core/src/main/java/org/springframework/util/ConcurrentReferenceHashMap.java b/spring-core/src/main/java/org/springframework/util/ConcurrentReferenceHashMap.java index b394d90b3e..794f64c3db 100644 --- a/spring-core/src/main/java/org/springframework/util/ConcurrentReferenceHashMap.java +++ b/spring-core/src/main/java/org/springframework/util/ConcurrentReferenceHashMap.java @@ -33,6 +33,8 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.locks.ReentrantLock; +import org.springframework.lang.Nullable; + /** * A {@link ConcurrentHashMap} that uses {@link ReferenceType#SOFT soft} or * {@linkplain ReferenceType#WEAK weak} references for both {@code keys} and {@code values}. @@ -210,7 +212,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen * @param o the object to hash (may be null) * @return the resulting hash code */ - protected int getHash(Object o) { + protected int getHash(@Nullable Object o) { int hash = o == null ? 0 : o.hashCode(); hash += (hash << 15) ^ 0xffffcd7d; hash ^= (hash >>> 10); @@ -242,7 +244,8 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen * @param restructure types of restructure allowed during this call * @return the reference, or {@code null} if not found */ - protected final Reference getReference(Object key, Restructure restructure) { + @Nullable + protected final Reference getReference(@Nullable Object key, Restructure restructure) { int hash = getHash(key); return getSegmentForHash(hash).getReference(key, hash, restructure); } @@ -317,6 +320,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen } @Override + @Nullable public V replace(K key, final V value) { return doTask(key, new Task(TaskOption.RESTRUCTURE_BEFORE, TaskOption.SKIP_IF_EMPTY) { @Override @@ -443,6 +447,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen setReferences(createReferenceArray(this.initialSize)); } + @Nullable public Reference getReference(Object key, int hash, Restructure restructure) { if (restructure == Restructure.WHEN_NECESSARY) { restructureIfNecessary(false); @@ -582,6 +587,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen } } + @Nullable private Reference findInChain(Reference reference, Object key, int hash) { while (reference != null) { if (reference.getHash() == hash) { @@ -643,6 +649,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen * available. * @return the entry or {@code null} */ + @Nullable Entry get(); /** @@ -655,6 +662,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen * Returns the next reference in the chain or {@code null} * @return the next reference of {@code null} */ + @Nullable Reference getNext(); /** @@ -745,7 +753,8 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen * @return the result of the task * @see #execute(Reference, Entry) */ - protected T execute(Reference reference, Entry entry, Entries entries) { + @Nullable + protected T execute(@Nullable Reference reference, @Nullable Entry entry, Entries entries) { return execute(reference, entry); } @@ -756,7 +765,8 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen * @return the result of the task * @see #execute(Reference, Entry, Entries) */ - protected T execute(Reference reference, Entry entry) { + @Nullable + protected T execute(@Nullable Reference reference, @Nullable Entry entry) { return null; } } @@ -933,7 +943,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen * @param next the next reference in the chain or {@code null} * @return a new {@link Reference} */ - public Reference createReference(Entry entry, int hash, Reference next) { + public Reference createReference(Entry entry, int hash, @Nullable Reference next) { if (ConcurrentReferenceHashMap.this.referenceType == ReferenceType.WEAK) { return new WeakEntryReference<>(entry, hash, next, this.queue); } @@ -948,6 +958,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen * @return a reference to purge or {@code null} */ @SuppressWarnings("unchecked") + @Nullable public Reference pollForPurge() { return (Reference) this.queue.poll(); } diff --git a/spring-core/src/main/java/org/springframework/util/CustomizableThreadCreator.java b/spring-core/src/main/java/org/springframework/util/CustomizableThreadCreator.java index d8338d3bf3..5499182675 100644 --- a/spring-core/src/main/java/org/springframework/util/CustomizableThreadCreator.java +++ b/spring-core/src/main/java/org/springframework/util/CustomizableThreadCreator.java @@ -19,6 +19,8 @@ package org.springframework.util; import java.io.Serializable; import java.util.concurrent.atomic.AtomicInteger; +import org.springframework.lang.Nullable; + /** * Simple customizable helper class for creating new {@link Thread} instances. * Provides various bean properties: thread name prefix, thread priority, etc. @@ -133,6 +135,7 @@ public class CustomizableThreadCreator implements Serializable { * Return the thread group that threads should be created in * (or {@code null} for the default group). */ + @Nullable public ThreadGroup getThreadGroup() { return this.threadGroup; } diff --git a/spring-core/src/main/java/org/springframework/util/FileCopyUtils.java b/spring-core/src/main/java/org/springframework/util/FileCopyUtils.java index 6c85061985..3c933b23b5 100644 --- a/spring-core/src/main/java/org/springframework/util/FileCopyUtils.java +++ b/spring-core/src/main/java/org/springframework/util/FileCopyUtils.java @@ -30,6 +30,8 @@ import java.io.Reader; import java.io.StringWriter; import java.io.Writer; +import org.springframework.lang.Nullable; + /** * Simple utility methods for file and stream copying. All copy methods use a block size * of 4096 bytes, and close all affected streams when done. A variation of the copy @@ -156,7 +158,7 @@ public abstract class FileCopyUtils { * @return the new byte array that has been copied to (possibly empty) * @throws IOException in case of I/O errors */ - public static byte[] copyToByteArray(InputStream in) throws IOException { + public static byte[] copyToByteArray(@Nullable InputStream in) throws IOException { if (in == null) { return new byte[0]; } @@ -238,7 +240,7 @@ public abstract class FileCopyUtils { * @return the String that has been copied to (possibly empty) * @throws IOException in case of I/O errors */ - public static String copyToString(Reader in) throws IOException { + public static String copyToString(@Nullable Reader in) throws IOException { if (in == null) { return ""; } diff --git a/spring-core/src/main/java/org/springframework/util/InstanceFilter.java b/spring-core/src/main/java/org/springframework/util/InstanceFilter.java index f97eb97847..96d71e1be2 100644 --- a/spring-core/src/main/java/org/springframework/util/InstanceFilter.java +++ b/spring-core/src/main/java/org/springframework/util/InstanceFilter.java @@ -19,6 +19,8 @@ package org.springframework.util; import java.util.Collection; import java.util.Collections; +import org.springframework.lang.Nullable; + /** * A simple instance filter that checks if a given instance match based on * a collection of includes and excludes element. @@ -101,7 +103,7 @@ public class InstanceFilter { * @param candidates a list of candidates * @return {@code true} if the instance match or the candidates collection is null */ - protected boolean match(T instance, Collection candidates) { + protected boolean match(@Nullable T instance, Collection candidates) { for (T candidate : candidates) { if (match(instance, candidate)) { return true; diff --git a/spring-core/src/main/java/org/springframework/util/LinkedCaseInsensitiveMap.java b/spring-core/src/main/java/org/springframework/util/LinkedCaseInsensitiveMap.java index 268fc11259..e5d02860c0 100644 --- a/spring-core/src/main/java/org/springframework/util/LinkedCaseInsensitiveMap.java +++ b/spring-core/src/main/java/org/springframework/util/LinkedCaseInsensitiveMap.java @@ -24,6 +24,8 @@ import java.util.Locale; import java.util.Map; import java.util.Set; +import org.springframework.lang.Nullable; + /** * {@link LinkedHashMap} variant that stores String keys in a case-insensitive * manner, for example for key-based access in a results table. @@ -134,6 +136,7 @@ public class LinkedCaseInsensitiveMap implements Map, Serializable } @Override + @Nullable public V get(Object key) { if (key instanceof String) { String caseInsensitiveKey = this.caseInsensitiveKeys.get(convertKey((String) key)); @@ -173,6 +176,7 @@ public class LinkedCaseInsensitiveMap implements Map, Serializable } @Override + @Nullable public V remove(Object key) { if (key instanceof String) { String caseInsensitiveKey = this.caseInsensitiveKeys.remove(convertKey((String) key)); diff --git a/spring-core/src/main/java/org/springframework/util/MethodInvoker.java b/spring-core/src/main/java/org/springframework/util/MethodInvoker.java index d2331caf09..9fa99c719f 100644 --- a/spring-core/src/main/java/org/springframework/util/MethodInvoker.java +++ b/spring-core/src/main/java/org/springframework/util/MethodInvoker.java @@ -20,6 +20,8 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; +import org.springframework.lang.Nullable; + /** * Helper class that allows for specifying a method to invoke in a declarative * fashion, be it static or non-static. @@ -201,6 +203,7 @@ public class MethodInvoker { * @see #getTargetMethod() * @see #getArguments() */ + @Nullable protected Method findMatchingMethod() { String targetMethod = getTargetMethod(); Object[] arguments = getArguments(); @@ -258,6 +261,7 @@ public class MethodInvoker { * @throws IllegalAccessException if the target method couldn't be accessed * @see #prepare */ + @Nullable public Object invoke() throws InvocationTargetException, IllegalAccessException { // In the static case, target will simply be {@code null}. Object targetObject = getTargetObject(); diff --git a/spring-core/src/main/java/org/springframework/util/MimeType.java b/spring-core/src/main/java/org/springframework/util/MimeType.java index a2ff8055ca..a32292c493 100644 --- a/spring-core/src/main/java/org/springframework/util/MimeType.java +++ b/spring-core/src/main/java/org/springframework/util/MimeType.java @@ -28,6 +28,8 @@ import java.util.Locale; import java.util.Map; import java.util.TreeSet; +import org.springframework.lang.Nullable; + /** * Represents a MIME Type, as originally defined in RFC 2046 and subsequently used in * other Internet protocols including HTTP. @@ -153,7 +155,7 @@ public class MimeType implements Comparable, Serializable { * @param parameters the parameters, may be {@code null} * @throws IllegalArgumentException if any of the parameters contains illegal characters */ - public MimeType(MimeType other, Map parameters) { + public MimeType(MimeType other, @Nullable Map parameters) { this(other.getType(), other.getSubtype(), parameters); } @@ -164,7 +166,7 @@ public class MimeType implements Comparable, Serializable { * @param parameters the parameters, may be {@code null} * @throws IllegalArgumentException if any of the parameters contains illegal characters */ - public MimeType(String type, String subtype, Map parameters) { + public MimeType(String type, String subtype, @Nullable Map parameters) { Assert.hasLength(type, "'type' must not be empty"); Assert.hasLength(subtype, "'subtype' must not be empty"); checkToken(type); @@ -276,6 +278,7 @@ public class MimeType implements Comparable, Serializable { * @return the character set, or {@code null} if not available * @since 4.3 */ + @Nullable public Charset getCharset() { String charset = getParameter(PARAM_CHARSET); return (charset != null ? Charset.forName(unquote(charset)) : null); @@ -286,6 +289,7 @@ public class MimeType implements Comparable, Serializable { * @param name the parameter name * @return the parameter value, or {@code null} if not present */ + @Nullable public String getParameter(String name) { return this.parameters.get(name); } diff --git a/spring-core/src/main/java/org/springframework/util/MultiValueMap.java b/spring-core/src/main/java/org/springframework/util/MultiValueMap.java index 8076e2fc0c..bf9791e8a6 100644 --- a/spring-core/src/main/java/org/springframework/util/MultiValueMap.java +++ b/spring-core/src/main/java/org/springframework/util/MultiValueMap.java @@ -19,6 +19,8 @@ package org.springframework.util; import java.util.List; import java.util.Map; +import org.springframework.lang.Nullable; + /** * Extension of the {@code Map} interface that stores multiple values. * @@ -32,6 +34,7 @@ public interface MultiValueMap extends Map> { * @param key the key * @return the first value for the specified key, or {@code null} */ + @Nullable V getFirst(K key); /** diff --git a/spring-core/src/main/java/org/springframework/util/ObjectUtils.java b/spring-core/src/main/java/org/springframework/util/ObjectUtils.java index f85af56978..75d7f59f45 100644 --- a/spring-core/src/main/java/org/springframework/util/ObjectUtils.java +++ b/spring-core/src/main/java/org/springframework/util/ObjectUtils.java @@ -22,6 +22,8 @@ import java.util.Collection; import java.util.Map; import java.util.Optional; +import org.springframework.lang.Nullable; + /** * Miscellaneous object utility methods. * @@ -102,7 +104,7 @@ public abstract class ObjectUtils { * @param array the array to check * @see #isEmpty(Object) */ - public static boolean isEmpty(Object[] array) { + public static boolean isEmpty(@Nullable Object[] array) { return (array == null || array.length == 0); } @@ -129,7 +131,7 @@ public abstract class ObjectUtils { * @see CollectionUtils#isEmpty(java.util.Map) */ @SuppressWarnings("rawtypes") - public static boolean isEmpty(Object obj) { + public static boolean isEmpty(@Nullable Object obj) { if (obj == null) { return true; } @@ -161,6 +163,7 @@ public abstract class ObjectUtils { * if the {@code Optional} is empty, or simply the given object as-is * @since 5.0 */ + @Nullable public static Object unwrapOptional(Object obj) { if (obj instanceof Optional) { Optional optional = (Optional) obj; @@ -181,7 +184,7 @@ public abstract class ObjectUtils { * @param element the element to check for * @return whether the element has been found in the given array */ - public static boolean containsElement(Object[] array, Object element) { + public static boolean containsElement(@Nullable Object[] array, Object element) { if (array == null) { return false; } @@ -248,7 +251,7 @@ public abstract class ObjectUtils { * @param obj the object to append * @return the new array (of the same component type; never {@code null}) */ - public static A[] addObjectToArray(A[] array, O obj) { + public static A[] addObjectToArray(@Nullable A[] array, O obj) { Class compType = Object.class; if (array != null) { compType = array.getClass().getComponentType(); @@ -275,7 +278,7 @@ public abstract class ObjectUtils { * @return the corresponding object array (never {@code null}) * @throws IllegalArgumentException if the parameter is not an array */ - public static Object[] toObjectArray(Object source) { + public static Object[] toObjectArray(@Nullable Object source) { if (source instanceof Object[]) { return (Object[]) source; } @@ -313,7 +316,7 @@ public abstract class ObjectUtils { * @see Object#equals(Object) * @see java.util.Arrays#equals */ - public static boolean nullSafeEquals(Object o1, Object o2) { + public static boolean nullSafeEquals(@Nullable Object o1, @Nullable Object o2) { if (o1 == o2) { return true; } @@ -386,7 +389,7 @@ public abstract class ObjectUtils { * @see #nullSafeHashCode(long[]) * @see #nullSafeHashCode(short[]) */ - public static int nullSafeHashCode(Object obj) { + public static int nullSafeHashCode(@Nullable Object obj) { if (obj == null) { return 0; } @@ -426,7 +429,7 @@ public abstract class ObjectUtils { * Return a hash code based on the contents of the specified array. * If {@code array} is {@code null}, this method returns 0. */ - public static int nullSafeHashCode(Object[] array) { + public static int nullSafeHashCode(@Nullable Object[] array) { if (array == null) { return 0; } @@ -441,7 +444,7 @@ public abstract class ObjectUtils { * Return a hash code based on the contents of the specified array. * If {@code array} is {@code null}, this method returns 0. */ - public static int nullSafeHashCode(boolean[] array) { + public static int nullSafeHashCode(@Nullable boolean[] array) { if (array == null) { return 0; } @@ -456,7 +459,7 @@ public abstract class ObjectUtils { * Return a hash code based on the contents of the specified array. * If {@code array} is {@code null}, this method returns 0. */ - public static int nullSafeHashCode(byte[] array) { + public static int nullSafeHashCode(@Nullable byte[] array) { if (array == null) { return 0; } @@ -471,7 +474,7 @@ public abstract class ObjectUtils { * Return a hash code based on the contents of the specified array. * If {@code array} is {@code null}, this method returns 0. */ - public static int nullSafeHashCode(char[] array) { + public static int nullSafeHashCode(@Nullable char[] array) { if (array == null) { return 0; } @@ -486,7 +489,7 @@ public abstract class ObjectUtils { * Return a hash code based on the contents of the specified array. * If {@code array} is {@code null}, this method returns 0. */ - public static int nullSafeHashCode(double[] array) { + public static int nullSafeHashCode(@Nullable double[] array) { if (array == null) { return 0; } @@ -501,7 +504,7 @@ public abstract class ObjectUtils { * Return a hash code based on the contents of the specified array. * If {@code array} is {@code null}, this method returns 0. */ - public static int nullSafeHashCode(float[] array) { + public static int nullSafeHashCode(@Nullable float[] array) { if (array == null) { return 0; } @@ -516,7 +519,7 @@ public abstract class ObjectUtils { * Return a hash code based on the contents of the specified array. * If {@code array} is {@code null}, this method returns 0. */ - public static int nullSafeHashCode(int[] array) { + public static int nullSafeHashCode(@Nullable int[] array) { if (array == null) { return 0; } @@ -531,7 +534,7 @@ public abstract class ObjectUtils { * Return a hash code based on the contents of the specified array. * If {@code array} is {@code null}, this method returns 0. */ - public static int nullSafeHashCode(long[] array) { + public static int nullSafeHashCode(@Nullable long[] array) { if (array == null) { return 0; } @@ -546,7 +549,7 @@ public abstract class ObjectUtils { * Return a hash code based on the contents of the specified array. * If {@code array} is {@code null}, this method returns 0. */ - public static int nullSafeHashCode(short[] array) { + public static int nullSafeHashCode(@Nullable short[] array) { if (array == null) { return 0; } @@ -604,7 +607,7 @@ public abstract class ObjectUtils { * @return the object's identity as String representation, * or an empty String if the object was {@code null} */ - public static String identityToString(Object obj) { + public static String identityToString(@Nullable Object obj) { if (obj == null) { return EMPTY_STRING; } @@ -629,7 +632,7 @@ public abstract class ObjectUtils { * @return a display String representation of {@code obj} * @see #nullSafeToString(Object) */ - public static String getDisplayString(Object obj) { + public static String getDisplayString(@Nullable Object obj) { if (obj == null) { return EMPTY_STRING; } @@ -642,7 +645,7 @@ public abstract class ObjectUtils { * @param obj the object to introspect (may be {@code null}) * @return the corresponding class name */ - public static String nullSafeClassName(Object obj) { + public static String nullSafeClassName(@Nullable Object obj) { return (obj != null ? obj.getClass().getName() : NULL_STRING); } @@ -653,7 +656,7 @@ public abstract class ObjectUtils { * @param obj the object to build a String representation for * @return a String representation of {@code obj} */ - public static String nullSafeToString(Object obj) { + public static String nullSafeToString(@Nullable Object obj) { if (obj == null) { return NULL_STRING; } @@ -700,7 +703,7 @@ public abstract class ObjectUtils { * @param array the array to build a String representation for * @return a String representation of {@code array} */ - public static String nullSafeToString(Object[] array) { + public static String nullSafeToString(@Nullable Object[] array) { if (array == null) { return NULL_STRING; } @@ -731,7 +734,7 @@ public abstract class ObjectUtils { * @param array the array to build a String representation for * @return a String representation of {@code array} */ - public static String nullSafeToString(boolean[] array) { + public static String nullSafeToString(@Nullable boolean[] array) { if (array == null) { return NULL_STRING; } @@ -763,7 +766,7 @@ public abstract class ObjectUtils { * @param array the array to build a String representation for * @return a String representation of {@code array} */ - public static String nullSafeToString(byte[] array) { + public static String nullSafeToString(@Nullable byte[] array) { if (array == null) { return NULL_STRING; } @@ -794,7 +797,7 @@ public abstract class ObjectUtils { * @param array the array to build a String representation for * @return a String representation of {@code array} */ - public static String nullSafeToString(char[] array) { + public static String nullSafeToString(@Nullable char[] array) { if (array == null) { return NULL_STRING; } @@ -825,7 +828,7 @@ public abstract class ObjectUtils { * @param array the array to build a String representation for * @return a String representation of {@code array} */ - public static String nullSafeToString(double[] array) { + public static String nullSafeToString(@Nullable double[] array) { if (array == null) { return NULL_STRING; } @@ -857,7 +860,7 @@ public abstract class ObjectUtils { * @param array the array to build a String representation for * @return a String representation of {@code array} */ - public static String nullSafeToString(float[] array) { + public static String nullSafeToString(@Nullable float[] array) { if (array == null) { return NULL_STRING; } @@ -889,7 +892,7 @@ public abstract class ObjectUtils { * @param array the array to build a String representation for * @return a String representation of {@code array} */ - public static String nullSafeToString(int[] array) { + public static String nullSafeToString(@Nullable int[] array) { if (array == null) { return NULL_STRING; } @@ -920,7 +923,7 @@ public abstract class ObjectUtils { * @param array the array to build a String representation for * @return a String representation of {@code array} */ - public static String nullSafeToString(long[] array) { + public static String nullSafeToString(@Nullable long[] array) { if (array == null) { return NULL_STRING; } @@ -951,7 +954,7 @@ public abstract class ObjectUtils { * @param array the array to build a String representation for * @return a String representation of {@code array} */ - public static String nullSafeToString(short[] array) { + public static String nullSafeToString(@Nullable short[] array) { if (array == null) { return NULL_STRING; } diff --git a/spring-core/src/main/java/org/springframework/util/PropertyPlaceholderHelper.java b/spring-core/src/main/java/org/springframework/util/PropertyPlaceholderHelper.java index 553d72d7da..233dd6d710 100644 --- a/spring-core/src/main/java/org/springframework/util/PropertyPlaceholderHelper.java +++ b/spring-core/src/main/java/org/springframework/util/PropertyPlaceholderHelper.java @@ -25,6 +25,8 @@ import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.lang.Nullable; + /** * Utility class for working with Strings that have placeholder values in them. A placeholder takes the form * {@code ${name}}. Using {@code PropertyPlaceholderHelper} these placeholders can be substituted for @@ -79,7 +81,7 @@ public class PropertyPlaceholderHelper { * be ignored ({@code true}) or cause an exception ({@code false}) */ public PropertyPlaceholderHelper(String placeholderPrefix, String placeholderSuffix, - String valueSeparator, boolean ignoreUnresolvablePlaceholders) { + @Nullable String valueSeparator, boolean ignoreUnresolvablePlaceholders) { Assert.notNull(placeholderPrefix, "'placeholderPrefix' must not be null"); Assert.notNull(placeholderSuffix, "'placeholderSuffix' must not be null"); @@ -220,6 +222,7 @@ public class PropertyPlaceholderHelper { * @param placeholderName the name of the placeholder to resolve * @return the replacement value, or {@code null} if no replacement is to be made */ + @Nullable String resolvePlaceholder(String placeholderName); } diff --git a/spring-core/src/main/java/org/springframework/util/ReflectionUtils.java b/spring-core/src/main/java/org/springframework/util/ReflectionUtils.java index 434ce082c3..b6655ba2b9 100644 --- a/spring-core/src/main/java/org/springframework/util/ReflectionUtils.java +++ b/spring-core/src/main/java/org/springframework/util/ReflectionUtils.java @@ -29,6 +29,8 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; +import org.springframework.lang.Nullable; + /** * Simple utility class for working with the reflection API and handling * reflection exceptions. @@ -75,6 +77,7 @@ public abstract class ReflectionUtils { * @param name the name of the field * @return the corresponding Field object, or {@code null} if not found */ + @Nullable public static Field findField(Class clazz, String name) { return findField(clazz, name, null); } @@ -88,7 +91,8 @@ public abstract class ReflectionUtils { * @param type the type of the field (may be {@code null} if name is specified) * @return the corresponding Field object, or {@code null} if not found */ - public static Field findField(Class clazz, String name, Class type) { + @Nullable + public static Field findField(Class clazz, @Nullable String name, @Nullable Class type) { Assert.notNull(clazz, "Class must not be null"); Assert.isTrue(name != null || type != null, "Either name or type of the field must be specified"); Class searchType = clazz; @@ -115,6 +119,7 @@ public abstract class ReflectionUtils { * @param target the target object on which to set the field * @param value the value to set (may be {@code null}) */ + @Nullable public static void setField(Field field, Object target, Object value) { try { field.set(target, value); @@ -155,6 +160,7 @@ public abstract class ReflectionUtils { * @param name the name of the method * @return the Method object, or {@code null} if none found */ + @Nullable public static Method findMethod(Class clazz, String name) { return findMethod(clazz, name, new Class[0]); } @@ -169,7 +175,8 @@ public abstract class ReflectionUtils { * (may be {@code null} to indicate any signature) * @return the Method object, or {@code null} if none found */ - public static Method findMethod(Class clazz, String name, Class... paramTypes) { + @Nullable + public static Method findMethod(Class clazz, String name, @Nullable Class... paramTypes) { Assert.notNull(clazz, "Class must not be null"); Assert.notNull(name, "Method name must not be null"); Class searchType = clazz; @@ -195,7 +202,8 @@ public abstract class ReflectionUtils { * @return the invocation result, if any * @see #invokeMethod(java.lang.reflect.Method, Object, Object[]) */ - public static Object invokeMethod(Method method, Object target) { + @Nullable + public static Object invokeMethod(Method method, @Nullable Object target) { return invokeMethod(method, target, new Object[0]); } @@ -209,7 +217,8 @@ public abstract class ReflectionUtils { * @param args the invocation arguments (may be {@code null}) * @return the invocation result, if any */ - public static Object invokeMethod(Method method, Object target, Object... args) { + @Nullable + public static Object invokeMethod(Method method, @Nullable Object target, @Nullable Object... args) { try { return method.invoke(target, args); } @@ -228,6 +237,7 @@ public abstract class ReflectionUtils { * @throws SQLException the JDBC API SQLException to rethrow (if any) * @see #invokeJdbcMethod(java.lang.reflect.Method, Object, Object[]) */ + @Nullable public static Object invokeJdbcMethod(Method method, Object target) throws SQLException { return invokeJdbcMethod(method, target, new Object[0]); } @@ -242,7 +252,8 @@ public abstract class ReflectionUtils { * @throws SQLException the JDBC API SQLException to rethrow (if any) * @see #invokeMethod(java.lang.reflect.Method, Object, Object[]) */ - public static Object invokeJdbcMethod(Method method, Object target, Object... args) throws SQLException { + @Nullable + public static Object invokeJdbcMethod(Method method, Object target, @Nullable Object... args) throws SQLException { try { return method.invoke(target, args); } diff --git a/spring-core/src/main/java/org/springframework/util/StopWatch.java b/spring-core/src/main/java/org/springframework/util/StopWatch.java index 997e7c5507..97dedce033 100644 --- a/spring-core/src/main/java/org/springframework/util/StopWatch.java +++ b/spring-core/src/main/java/org/springframework/util/StopWatch.java @@ -20,6 +20,8 @@ import java.text.NumberFormat; import java.util.LinkedList; import java.util.List; +import org.springframework.lang.Nullable; + /** * Simple stop watch, allowing for timing of a number of tasks, * exposing total running time and running time for each named task. @@ -165,6 +167,7 @@ public class StopWatch { * @since 4.2.2 * @see #isRunning() */ + @Nullable public String currentTaskName() { return this.currentTaskName; } diff --git a/spring-core/src/main/java/org/springframework/util/StreamUtils.java b/spring-core/src/main/java/org/springframework/util/StreamUtils.java index d3374bc3ed..227f124141 100644 --- a/spring-core/src/main/java/org/springframework/util/StreamUtils.java +++ b/spring-core/src/main/java/org/springframework/util/StreamUtils.java @@ -28,6 +28,8 @@ import java.io.OutputStreamWriter; import java.io.Writer; import java.nio.charset.Charset; +import org.springframework.lang.Nullable; + /** * Simple utility methods for dealing with streams. The copy methods of this class are * similar to those defined in {@link FileCopyUtils} except that all affected streams are @@ -55,7 +57,7 @@ public abstract class StreamUtils { * @return the new byte array that has been copied to (possibly empty) * @throws IOException in case of I/O errors */ - public static byte[] copyToByteArray(InputStream in) throws IOException { + public static byte[] copyToByteArray(@Nullable InputStream in) throws IOException { if (in == null) { return new byte[0]; } @@ -72,7 +74,7 @@ public abstract class StreamUtils { * @return the String that has been copied to (possibly empty) * @throws IOException in case of I/O errors */ - public static String copyToString(InputStream in, Charset charset) throws IOException { + public static String copyToString(@Nullable InputStream in, Charset charset) throws IOException { if (in == null) { return ""; } diff --git a/spring-core/src/main/java/org/springframework/util/StringUtils.java b/spring-core/src/main/java/org/springframework/util/StringUtils.java index 7de1430c5d..1cf25b3775 100644 --- a/spring-core/src/main/java/org/springframework/util/StringUtils.java +++ b/spring-core/src/main/java/org/springframework/util/StringUtils.java @@ -33,6 +33,8 @@ import java.util.Set; import java.util.StringTokenizer; import java.util.TimeZone; +import org.springframework.lang.Nullable; + /** * Miscellaneous {@link String} utility methods. * @@ -83,7 +85,7 @@ public abstract class StringUtils { * @param str the candidate String * @since 3.2.1 */ - public static boolean isEmpty(Object str) { + public static boolean isEmpty(@Nullable Object str) { return (str == null || "".equals(str)); } @@ -102,7 +104,7 @@ public abstract class StringUtils { * @return {@code true} if the {@code CharSequence} is not {@code null} and has length * @see #hasText(String) */ - public static boolean hasLength(CharSequence str) { + public static boolean hasLength(@Nullable CharSequence str) { return (str != null && str.length() > 0); } @@ -115,7 +117,7 @@ public abstract class StringUtils { * @see #hasLength(CharSequence) * @see #hasText(String) */ - public static boolean hasLength(String str) { + public static boolean hasLength(@Nullable String str) { return hasLength((CharSequence) str); } @@ -136,7 +138,7 @@ public abstract class StringUtils { * its length is greater than 0, and it does not contain whitespace only * @see Character#isWhitespace */ - public static boolean hasText(CharSequence str) { + public static boolean hasText(@Nullable CharSequence str) { if (!hasLength(str)) { return false; } @@ -160,7 +162,7 @@ public abstract class StringUtils { * length is greater than 0, and it does not contain whitespace only * @see #hasText(CharSequence) */ - public static boolean hasText(String str) { + public static boolean hasText(@Nullable String str) { return hasText((CharSequence) str); } @@ -171,7 +173,7 @@ public abstract class StringUtils { * contains at least 1 whitespace character * @see Character#isWhitespace */ - public static boolean containsWhitespace(CharSequence str) { + public static boolean containsWhitespace(@Nullable CharSequence str) { if (!hasLength(str)) { return false; } @@ -192,7 +194,7 @@ public abstract class StringUtils { * contains at least 1 whitespace character * @see #containsWhitespace(CharSequence) */ - public static boolean containsWhitespace(String str) { + public static boolean containsWhitespace(@Nullable String str) { return containsWhitespace((CharSequence) str); } @@ -381,7 +383,7 @@ public abstract class StringUtils { * @param str string to search in. Return 0 if this is {@code null}. * @param sub string to search for. Return 0 if this is {@code null}. */ - public static int countOccurrencesOf(String str, String sub) { + public static int countOccurrencesOf(@Nullable String str, @Nullable String sub) { if (!hasLength(str) || !hasLength(sub)) { return 0; } @@ -477,7 +479,8 @@ public abstract class StringUtils { * @return the quoted {@code String} (e.g. "'myString'"), * or {@code null} if the input was {@code null} */ - public static String quote(String str) { + @Nullable + public static String quote(@Nullable String str) { return (str != null ? "'" + str + "'" : null); } @@ -519,7 +522,8 @@ public abstract class StringUtils { * @return the capitalized {@code String}, or {@code null} if the supplied * string is {@code null} */ - public static String capitalize(String str) { + @Nullable + public static String capitalize(@Nullable String str) { return changeFirstCharacterCase(str, true); } @@ -531,7 +535,8 @@ public abstract class StringUtils { * @return the uncapitalized {@code String}, or {@code null} if the supplied * string is {@code null} */ - public static String uncapitalize(String str) { + @Nullable + public static String uncapitalize(@Nullable String str) { return changeFirstCharacterCase(str, false); } @@ -563,7 +568,8 @@ public abstract class StringUtils { * @param path the file path (may be {@code null}) * @return the extracted filename, or {@code null} if none */ - public static String getFilename(String path) { + @Nullable + public static String getFilename(@Nullable String path) { if (path == null) { return null; } @@ -578,7 +584,8 @@ public abstract class StringUtils { * @param path the file path (may be {@code null}) * @return the extracted filename extension, or {@code null} if none */ - public static String getFilenameExtension(String path) { + @Nullable + public static String getFilenameExtension(@Nullable String path) { if (path == null) { return null; } @@ -603,7 +610,8 @@ public abstract class StringUtils { * @return the path with stripped filename extension, * or {@code null} if none */ - public static String stripFilenameExtension(String path) { + @Nullable + public static String stripFilenameExtension(@Nullable String path) { if (path == null) { return null; } @@ -735,7 +743,8 @@ public abstract class StringUtils { * @since 5.0 * @see java.net.URLDecoder#decode(String, String) */ - public static String uriDecode(String source, Charset charset) { + @Nullable + public static String uriDecode(@Nullable String source, Charset charset) { if (source == null) { return null; } @@ -853,7 +862,7 @@ public abstract class StringUtils { * @param str the {@code String} to append * @return the new array (never {@code null}) */ - public static String[] addStringToArray(String[] array, String str) { + public static String[] addStringToArray(@Nullable String[] array, String str) { if (ObjectUtils.isEmpty(array)) { return new String[] {str}; } @@ -872,7 +881,8 @@ public abstract class StringUtils { * @param array2 the second array (can be {@code null}) * @return the new array ({@code null} if both given arrays were {@code null}) */ - public static String[] concatenateStringArrays(String[] array1, String[] array2) { + @Nullable + public static String[] concatenateStringArrays(@Nullable String[] array1, @Nullable String[] array2) { if (ObjectUtils.isEmpty(array1)) { return array2; } @@ -896,7 +906,8 @@ public abstract class StringUtils { * @param array2 the second array (can be {@code null}) * @return the new array ({@code null} if both given arrays were {@code null}) */ - public static String[] mergeStringArrays(String[] array1, String[] array2) { + @Nullable + public static String[] mergeStringArrays(@Nullable String[] array1, @Nullable String[] array2) { if (ObjectUtils.isEmpty(array1)) { return array2; } @@ -935,7 +946,8 @@ public abstract class StringUtils { * @return the {@code String} array ({@code null} if the supplied * {@code Collection} was {@code null}) */ - public static String[] toStringArray(Collection collection) { + @Nullable + public static String[] toStringArray(@Nullable Collection collection) { if (collection == null) { return null; } @@ -950,7 +962,8 @@ public abstract class StringUtils { * @return the {@code String} array ({@code null} if the passed-in * Enumeration was {@code null}) */ - public static String[] toStringArray(Enumeration enumeration) { + @Nullable + public static String[] toStringArray(@Nullable Enumeration enumeration) { if (enumeration == null) { return null; } @@ -1005,6 +1018,7 @@ public abstract class StringUtils { * index 1 being after the delimiter (neither element includes the delimiter); * or {@code null} if the delimiter wasn't found in the given input {@code String} */ + @Nullable public static String[] split(String toSplit, String delimiter) { if (!hasLength(toSplit) || !hasLength(delimiter)) { return null; @@ -1030,6 +1044,7 @@ public abstract class StringUtils { * @return a {@code Properties} instance representing the array contents, * or {@code null} if the array to process was {@code null} or empty */ + @Nullable public static Properties splitArrayElementsIntoProperties(String[] array, String delimiter) { return splitArrayElementsIntoProperties(array, delimiter, null); } @@ -1048,6 +1063,7 @@ public abstract class StringUtils { * @return a {@code Properties} instance representing the array contents, * or {@code null} if the array to process was {@code null} or empty */ + @Nullable public static Properties splitArrayElementsIntoProperties( String[] array, String delimiter, String charsToDelete) { @@ -1109,8 +1125,9 @@ public abstract class StringUtils { * @see String#trim() * @see #delimitedListToStringArray */ + @Nullable public static String[] tokenizeToStringArray( - String str, String delimiters, boolean trimTokens, boolean ignoreEmptyTokens) { + @Nullable String str, String delimiters, boolean trimTokens, boolean ignoreEmptyTokens) { if (str == null) { return null; diff --git a/spring-core/src/main/java/org/springframework/util/StringValueResolver.java b/spring-core/src/main/java/org/springframework/util/StringValueResolver.java index 8ed24ea7d2..61610cf5d4 100644 --- a/spring-core/src/main/java/org/springframework/util/StringValueResolver.java +++ b/spring-core/src/main/java/org/springframework/util/StringValueResolver.java @@ -16,6 +16,8 @@ package org.springframework.util; +import org.springframework.lang.Nullable; + /** * Simple strategy interface for resolving a String value. * Used by {@link org.springframework.beans.factory.config.ConfigurableBeanFactory}. @@ -37,6 +39,7 @@ public interface StringValueResolver { * to resolve or when ignoring unresolvable placeholders) * @throws IllegalArgumentException in case of an unresolvable String value */ - String resolveStringValue(String strVal); + @Nullable + String resolveStringValue(@Nullable String strVal); } diff --git a/spring-core/src/main/java/org/springframework/util/backoff/package-info.java b/spring-core/src/main/java/org/springframework/util/backoff/package-info.java index 6bace75723..e23152d773 100644 --- a/spring-core/src/main/java/org/springframework/util/backoff/package-info.java +++ b/spring-core/src/main/java/org/springframework/util/backoff/package-info.java @@ -1,4 +1,7 @@ /** * A generic back-off abstraction. */ +@NonNullApi package org.springframework.util.backoff; + +import org.springframework.lang.NonNullApi; diff --git a/spring-core/src/main/java/org/springframework/util/comparator/package-info.java b/spring-core/src/main/java/org/springframework/util/comparator/package-info.java index 27b860fed4..29821e3ae2 100644 --- a/spring-core/src/main/java/org/springframework/util/comparator/package-info.java +++ b/spring-core/src/main/java/org/springframework/util/comparator/package-info.java @@ -2,4 +2,7 @@ * Useful generic {@code java.util.Comparator} implementations, * such as an invertible comparator and a compound comparator. */ +@NonNullApi package org.springframework.util.comparator; + +import org.springframework.lang.NonNullApi; diff --git a/spring-core/src/main/java/org/springframework/util/concurrent/package-info.java b/spring-core/src/main/java/org/springframework/util/concurrent/package-info.java index 75b626eb29..5bc5f5d046 100644 --- a/spring-core/src/main/java/org/springframework/util/concurrent/package-info.java +++ b/spring-core/src/main/java/org/springframework/util/concurrent/package-info.java @@ -1,4 +1,7 @@ /** * Useful generic {@code java.util.concurrent.Future} extension. */ +@NonNullApi package org.springframework.util.concurrent; + +import org.springframework.lang.NonNullApi; diff --git a/spring-core/src/main/java/org/springframework/util/package-info.java b/spring-core/src/main/java/org/springframework/util/package-info.java index 7c6dd17d20..b1f68b55ab 100644 --- a/spring-core/src/main/java/org/springframework/util/package-info.java +++ b/spring-core/src/main/java/org/springframework/util/package-info.java @@ -2,4 +2,7 @@ * Miscellaneous utility classes, such as String manipulation utilities, * a Log4J configurer, and a state holder for paged lists of objects. */ +@NonNullApi package org.springframework.util; + +import org.springframework.lang.NonNullApi; diff --git a/spring-core/src/main/java/org/springframework/util/xml/AbstractXMLEventReader.java b/spring-core/src/main/java/org/springframework/util/xml/AbstractXMLEventReader.java index 12a934b981..79bc00a192 100644 --- a/spring-core/src/main/java/org/springframework/util/xml/AbstractXMLEventReader.java +++ b/spring-core/src/main/java/org/springframework/util/xml/AbstractXMLEventReader.java @@ -23,6 +23,7 @@ import javax.xml.stream.XMLStreamException; import javax.xml.stream.events.Characters; import javax.xml.stream.events.XMLEvent; +import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; /** @@ -78,6 +79,7 @@ abstract class AbstractXMLEventReader implements XMLEventReader { } @Override + @Nullable public XMLEvent nextTag() throws XMLStreamException { checkIfClosed(); while (true) { diff --git a/spring-core/src/main/java/org/springframework/util/xml/AbstractXMLStreamReader.java b/spring-core/src/main/java/org/springframework/util/xml/AbstractXMLStreamReader.java index 6335ea156f..dbb4c644a1 100644 --- a/spring-core/src/main/java/org/springframework/util/xml/AbstractXMLStreamReader.java +++ b/spring-core/src/main/java/org/springframework/util/xml/AbstractXMLStreamReader.java @@ -21,6 +21,7 @@ import javax.xml.stream.XMLStreamConstants; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -162,6 +163,7 @@ abstract class AbstractXMLStreamReader implements XMLStreamReader { } @Override + @Nullable public String getAttributeValue(String namespaceURI, String localName) { for (int i = 0; i < getAttributeCount(); i++) { QName name = getAttributeName(i); diff --git a/spring-core/src/main/java/org/springframework/util/xml/DomUtils.java b/spring-core/src/main/java/org/springframework/util/xml/DomUtils.java index 6d2988fd73..8a6c73fdfe 100644 --- a/spring-core/src/main/java/org/springframework/util/xml/DomUtils.java +++ b/spring-core/src/main/java/org/springframework/util/xml/DomUtils.java @@ -29,6 +29,7 @@ import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.xml.sax.ContentHandler; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -91,6 +92,7 @@ public abstract class DomUtils { * @param childEleName the child element name to look for * @return the {@code org.w3c.dom.Element} instance, or {@code null} if none found */ + @Nullable public static Element getChildElementByTagName(Element ele, String childEleName) { Assert.notNull(ele, "Element must not be null"); Assert.notNull(childEleName, "Element name must not be null"); @@ -110,6 +112,7 @@ public abstract class DomUtils { * @param childEleName the child element name to look for * @return the extracted text value, or {@code null} if no child element found */ + @Nullable public static String getChildElementValueByTagName(Element ele, String childEleName) { Element child = getChildElementByTagName(ele, childEleName); return (child != null ? getTextValue(child) : null); diff --git a/spring-core/src/main/java/org/springframework/util/xml/ListBasedXMLEventReader.java b/spring-core/src/main/java/org/springframework/util/xml/ListBasedXMLEventReader.java index 6abb577ea1..f409ee0d31 100644 --- a/spring-core/src/main/java/org/springframework/util/xml/ListBasedXMLEventReader.java +++ b/spring-core/src/main/java/org/springframework/util/xml/ListBasedXMLEventReader.java @@ -21,6 +21,7 @@ import java.util.List; import java.util.NoSuchElementException; import javax.xml.stream.events.XMLEvent; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -58,6 +59,7 @@ class ListBasedXMLEventReader extends AbstractXMLEventReader { } @Override + @Nullable public XMLEvent peek() { if (this.cursor < this.events.size()) { return this.events.get(this.cursor); diff --git a/spring-core/src/main/java/org/springframework/util/xml/StaxResult.java b/spring-core/src/main/java/org/springframework/util/xml/StaxResult.java index a8d9bfa26f..d805ecb7bd 100644 --- a/spring-core/src/main/java/org/springframework/util/xml/StaxResult.java +++ b/spring-core/src/main/java/org/springframework/util/xml/StaxResult.java @@ -23,6 +23,8 @@ import javax.xml.transform.sax.SAXResult; import org.xml.sax.ContentHandler; import org.xml.sax.ext.LexicalHandler; +import org.springframework.lang.Nullable; + /** * Implementation of the {@code Result} tagging interface for StAX writers. Can be constructed with * an {@code XMLEventConsumer} or an {@code XMLStreamWriter}. @@ -80,6 +82,7 @@ class StaxResult extends SAXResult { * @return the StAX event writer used by this result * @see #StaxResult(javax.xml.stream.XMLEventWriter) */ + @Nullable public XMLEventWriter getXMLEventWriter() { return this.eventWriter; } @@ -90,6 +93,7 @@ class StaxResult extends SAXResult { * @return the StAX stream writer used by this result * @see #StaxResult(javax.xml.stream.XMLStreamWriter) */ + @Nullable public XMLStreamWriter getXMLStreamWriter() { return this.streamWriter; } diff --git a/spring-core/src/main/java/org/springframework/util/xml/StaxSource.java b/spring-core/src/main/java/org/springframework/util/xml/StaxSource.java index 5706a4317e..bfddf82f28 100644 --- a/spring-core/src/main/java/org/springframework/util/xml/StaxSource.java +++ b/spring-core/src/main/java/org/springframework/util/xml/StaxSource.java @@ -23,6 +23,8 @@ import javax.xml.transform.sax.SAXSource; import org.xml.sax.InputSource; import org.xml.sax.XMLReader; +import org.springframework.lang.Nullable; + /** * Implementation of the {@code Source} tagging interface for StAX readers. Can be constructed with * an {@code XMLEventReader} or an {@code XMLStreamReader}. @@ -81,6 +83,7 @@ class StaxSource extends SAXSource { * @return the StAX event reader used by this source * @see StaxSource#StaxSource(javax.xml.stream.XMLEventReader) */ + @Nullable XMLEventReader getXMLEventReader() { return this.eventReader; } @@ -91,6 +94,7 @@ class StaxSource extends SAXSource { * @return the StAX event reader used by this source * @see StaxSource#StaxSource(javax.xml.stream.XMLEventReader) */ + @Nullable XMLStreamReader getXMLStreamReader() { return this.streamReader; } diff --git a/spring-core/src/main/java/org/springframework/util/xml/XMLEventStreamReader.java b/spring-core/src/main/java/org/springframework/util/xml/XMLEventStreamReader.java index 134cbdc68d..cd5c82ee17 100644 --- a/spring-core/src/main/java/org/springframework/util/xml/XMLEventStreamReader.java +++ b/spring-core/src/main/java/org/springframework/util/xml/XMLEventStreamReader.java @@ -29,6 +29,8 @@ import javax.xml.stream.events.ProcessingInstruction; import javax.xml.stream.events.StartDocument; import javax.xml.stream.events.XMLEvent; +import org.springframework.lang.Nullable; + /** * Implementation of the {@link javax.xml.stream.XMLStreamReader} interface that wraps a * {@link XMLEventReader}. Useful because the StAX {@link javax.xml.stream.XMLInputFactory} @@ -75,6 +77,7 @@ class XMLEventStreamReader extends AbstractXMLStreamReader { } @Override + @Nullable public String getVersion() { if (this.event.isStartDocument()) { return ((StartDocument) this.event).getVersion(); @@ -110,11 +113,13 @@ class XMLEventStreamReader extends AbstractXMLStreamReader { } @Override + @Nullable public String getEncoding() { return null; } @Override + @Nullable public String getCharacterEncodingScheme() { return null; } diff --git a/spring-core/src/main/java/org/springframework/util/xml/package-info.java b/spring-core/src/main/java/org/springframework/util/xml/package-info.java index 058f1c6411..7189bdb565 100644 --- a/spring-core/src/main/java/org/springframework/util/xml/package-info.java +++ b/spring-core/src/main/java/org/springframework/util/xml/package-info.java @@ -2,4 +2,7 @@ * Miscellaneous utility classes for XML parsing and transformation, * such as error handlers that log warnings via Commons Logging. */ +@NonNullApi package org.springframework.util.xml; + +import org.springframework.lang.NonNullApi; diff --git a/spring-expression/src/main/java/org/springframework/expression/ConstructorResolver.java b/spring-expression/src/main/java/org/springframework/expression/ConstructorResolver.java index 30255ac2e6..dc8e636c96 100644 --- a/spring-expression/src/main/java/org/springframework/expression/ConstructorResolver.java +++ b/spring-expression/src/main/java/org/springframework/expression/ConstructorResolver.java @@ -19,6 +19,7 @@ package org.springframework.expression; import java.util.List; import org.springframework.core.convert.TypeDescriptor; +import org.springframework.lang.Nullable; /** * A constructor resolver attempts locate a constructor and returns a ConstructorExecutor @@ -40,6 +41,7 @@ public interface ConstructorResolver { * @param argumentTypes the arguments that the constructor must be able to handle * @return a ConstructorExecutor that can invoke the constructor, or null if non found */ + @Nullable ConstructorExecutor resolve(EvaluationContext context, String typeName, List argumentTypes) throws AccessException; diff --git a/spring-expression/src/main/java/org/springframework/expression/MethodResolver.java b/spring-expression/src/main/java/org/springframework/expression/MethodResolver.java index e33dc8423f..9871ab8794 100644 --- a/spring-expression/src/main/java/org/springframework/expression/MethodResolver.java +++ b/spring-expression/src/main/java/org/springframework/expression/MethodResolver.java @@ -19,6 +19,7 @@ package org.springframework.expression; import java.util.List; import org.springframework.core.convert.TypeDescriptor; +import org.springframework.lang.Nullable; /** * A method resolver attempts locate a method and returns a command executor that can be @@ -39,6 +40,7 @@ public interface MethodResolver { * @param argumentTypes the arguments that the constructor must be able to handle * @return a MethodExecutor that can invoke the method, or null if the method cannot be found */ + @Nullable MethodExecutor resolve(EvaluationContext context, Object targetObject, String name, List argumentTypes) throws AccessException; diff --git a/spring-expression/src/main/java/org/springframework/expression/PropertyAccessor.java b/spring-expression/src/main/java/org/springframework/expression/PropertyAccessor.java index e6c78b14de..084a081890 100644 --- a/spring-expression/src/main/java/org/springframework/expression/PropertyAccessor.java +++ b/spring-expression/src/main/java/org/springframework/expression/PropertyAccessor.java @@ -17,6 +17,8 @@ package org.springframework.expression; +import org.springframework.lang.Nullable; + /** * A property accessor is able to read from (and possibly write to) an object's properties. * This interface places no restrictions, and so implementors are free to access properties @@ -43,6 +45,7 @@ public interface PropertyAccessor { * @return an array of classes that this resolver is suitable for * (or {@code null} if a general resolver) */ + @Nullable Class[] getSpecificTargetClasses(); /** diff --git a/spring-expression/src/main/java/org/springframework/expression/TypeConverter.java b/spring-expression/src/main/java/org/springframework/expression/TypeConverter.java index ee78104dca..6a012474ad 100644 --- a/spring-expression/src/main/java/org/springframework/expression/TypeConverter.java +++ b/spring-expression/src/main/java/org/springframework/expression/TypeConverter.java @@ -17,6 +17,7 @@ package org.springframework.expression; import org.springframework.core.convert.TypeDescriptor; +import org.springframework.lang.Nullable; /** * A type converter can convert values between different types encountered during @@ -53,6 +54,7 @@ public interface TypeConverter { * @return the converted value * @throws EvaluationException if conversion failed or is not possible to begin with */ + @Nullable Object convertValue(Object value, TypeDescriptor sourceType, TypeDescriptor targetType); } diff --git a/spring-expression/src/main/java/org/springframework/expression/common/package-info.java b/spring-expression/src/main/java/org/springframework/expression/common/package-info.java index 7cf633a44b..c572c5bdd1 100644 --- a/spring-expression/src/main/java/org/springframework/expression/common/package-info.java +++ b/spring-expression/src/main/java/org/springframework/expression/common/package-info.java @@ -1,4 +1,7 @@ /** * Common utility classes behind the Spring Expression Language. */ +@NonNullApi package org.springframework.expression.common; + +import org.springframework.lang.NonNullApi; diff --git a/spring-expression/src/main/java/org/springframework/expression/package-info.java b/spring-expression/src/main/java/org/springframework/expression/package-info.java index e7631cc36b..b01674cf18 100644 --- a/spring-expression/src/main/java/org/springframework/expression/package-info.java +++ b/spring-expression/src/main/java/org/springframework/expression/package-info.java @@ -1,4 +1,7 @@ /** * Core abstractions behind the Spring Expression Language. */ +@NonNullApi package org.springframework.expression; + +import org.springframework.lang.NonNullApi; diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/CodeFlow.java b/spring-expression/src/main/java/org/springframework/expression/spel/CodeFlow.java index 259215d052..9672f4cff3 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/CodeFlow.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/CodeFlow.java @@ -25,6 +25,7 @@ import java.util.Stack; import org.springframework.asm.ClassWriter; import org.springframework.asm.MethodVisitor; import org.springframework.asm.Opcodes; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -148,6 +149,7 @@ public class CodeFlow implements Opcodes { /** * Return the descriptor for the item currently on top of the stack (in the current scope). */ + @Nullable public String lastDescriptor() { if (this.compilationScopes.peek().isEmpty()) { return null; @@ -508,7 +510,8 @@ public class CodeFlow implements Opcodes { * @return the type descriptor for the object * (descriptor is "Ljava/lang/Object" for {@code null} value) */ - public static String toDescriptorFromObject(Object value) { + @Nullable + public static String toDescriptorFromObject(@Nullable Object value) { if (value == null) { return "Ljava/lang/Object"; } @@ -768,6 +771,7 @@ public class CodeFlow implements Opcodes { * @param type the type (may be primitive) for which to determine the descriptor * @return the descriptor */ + @Nullable public static String toDescriptor(Class type) { String name = type.getName(); if (type.isPrimitive()) { diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/ExpressionState.java b/spring-expression/src/main/java/org/springframework/expression/spel/ExpressionState.java index 7b45e34ba5..e1cbfbd453 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/ExpressionState.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/ExpressionState.java @@ -31,6 +31,7 @@ import org.springframework.expression.PropertyAccessor; import org.springframework.expression.TypeComparator; import org.springframework.expression.TypeConverter; import org.springframework.expression.TypedValue; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -204,6 +205,7 @@ public class ExpressionState { this.variableScopes.peek().setVariable(name, value); } + @Nullable public Object lookupLocalVariable(String name) { ensureVariableScopesInitialized(); int scopeNumber = this.variableScopes.size() - 1; diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/SpelNode.java b/spring-expression/src/main/java/org/springframework/expression/spel/SpelNode.java index 1088a98e4f..fd527c93ed 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/SpelNode.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/SpelNode.java @@ -18,6 +18,7 @@ package org.springframework.expression.spel; import org.springframework.expression.EvaluationException; import org.springframework.expression.TypedValue; +import org.springframework.lang.Nullable; /** * Represents a node in the Ast for a parsed expression. @@ -85,6 +86,7 @@ public interface SpelNode { * @return the class of the object if it is not already a class object, * or {@code null} if the object is {@code null} */ + @Nullable Class getObjectClass(Object obj); /** diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/ast/ConstructorReference.java b/spring-expression/src/main/java/org/springframework/expression/spel/ast/ConstructorReference.java index 70cf696b89..fa56e3aba8 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/ast/ConstructorReference.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/ast/ConstructorReference.java @@ -39,6 +39,7 @@ import org.springframework.expression.spel.SpelEvaluationException; import org.springframework.expression.spel.SpelMessage; import org.springframework.expression.spel.SpelNode; import org.springframework.expression.spel.support.ReflectiveConstructorExecutor; +import org.springframework.lang.Nullable; /** * Represents the invocation of a constructor. Either a constructor on a regular type or @@ -178,6 +179,7 @@ public class ConstructorReference extends SpelNodeImpl { * @return a reusable ConstructorExecutor that can be invoked to run the constructor or null * @throws SpelEvaluationException if there is a problem locating the constructor */ + @Nullable private ConstructorExecutor findExecutorForConstructor(String typeName, List argumentTypes, ExpressionState state) throws SpelEvaluationException { diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/ast/MethodReference.java b/spring-expression/src/main/java/org/springframework/expression/spel/ast/MethodReference.java index 63831a5ab0..7618c2f7ef 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/ast/MethodReference.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/ast/MethodReference.java @@ -38,6 +38,7 @@ import org.springframework.expression.spel.SpelEvaluationException; import org.springframework.expression.spel.SpelMessage; import org.springframework.expression.spel.support.ReflectiveMethodExecutor; import org.springframework.expression.spel.support.ReflectiveMethodResolver; +import org.springframework.lang.Nullable; /** * Expression language AST node that represents a method reference. @@ -168,6 +169,7 @@ public class MethodReference extends SpelNodeImpl { return Collections.unmodifiableList(descriptors); } + @Nullable private MethodExecutor getCachedExecutor(EvaluationContext evaluationContext, Object value, TypeDescriptor target, List argumentTypes) { diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/ast/Operator.java b/spring-expression/src/main/java/org/springframework/expression/spel/ast/Operator.java index f033519e5a..c5103011d7 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/ast/Operator.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/ast/Operator.java @@ -23,6 +23,7 @@ import org.springframework.asm.Label; import org.springframework.asm.MethodVisitor; import org.springframework.expression.EvaluationContext; import org.springframework.expression.spel.CodeFlow; +import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.util.NumberUtils; import org.springframework.util.ObjectUtils; @@ -61,6 +62,7 @@ public abstract class Operator extends SpelNodeImpl { return this.children[0]; } + @Nullable public SpelNodeImpl getRightOperand() { return this.children[1]; } diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/ast/package-info.java b/spring-expression/src/main/java/org/springframework/expression/spel/ast/package-info.java index d601d80eee..d7fdffbbaf 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/ast/package-info.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/ast/package-info.java @@ -1,4 +1,7 @@ /** * SpEL's abstract syntax tree. */ +@NonNullApi package org.springframework.expression.spel.ast; + +import org.springframework.lang.NonNullApi; diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/package-info.java b/spring-expression/src/main/java/org/springframework/expression/spel/package-info.java index 89c07e63b1..7f1ca0322f 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/package-info.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/package-info.java @@ -1,4 +1,7 @@ /** * SpEL's central implementation package. */ +@NonNullApi package org.springframework.expression.spel; + +import org.springframework.lang.NonNullApi; diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/standard/InternalSpelExpressionParser.java b/spring-expression/src/main/java/org/springframework/expression/spel/standard/InternalSpelExpressionParser.java index 0f09391bce..16465eedbd 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/standard/InternalSpelExpressionParser.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/standard/InternalSpelExpressionParser.java @@ -72,6 +72,7 @@ import org.springframework.expression.spel.ast.StringLiteral; import org.springframework.expression.spel.ast.Ternary; import org.springframework.expression.spel.ast.TypeReference; import org.springframework.expression.spel.ast.VariableReference; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -374,6 +375,7 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser { } // nonDottedNode: indexer; + @Nullable private SpelNodeImpl maybeEatNonDottedNode() { if (peekToken(TokenKind.LSQUARE)) { if (maybeEatIndexer()) { @@ -392,6 +394,7 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser { // | lastSelection // )) // ; + @Nullable private SpelNodeImpl eatDottedNode() { Token t = nextToken(); // it was a '.' or a '?.' boolean nullSafeNavigation = (t.kind == TokenKind.SAFE_NAVI); @@ -434,6 +437,7 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser { } // methodArgs : LPAREN! (argument (COMMA! argument)* (COMMA!)?)? RPAREN!; + @Nullable private SpelNodeImpl[] maybeEatMethodArgs() { if (!peekToken(TokenKind.LPAREN)) { return null; @@ -497,6 +501,7 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser { // | lastSelection // | indexer // | constructor + @Nullable private SpelNodeImpl eatStartNode() { if (maybeEatLiteral()) { return pop(); @@ -888,6 +893,7 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser { // relationalOperator // : EQUAL | NOT_EQUAL | LESS_THAN | LESS_THAN_OR_EQUAL | GREATER_THAN // | GREATER_THAN_OR_EQUAL | INSTANCEOF | BETWEEN | MATCHES + @Nullable private Token maybeEatRelationalOperator() { Token t = peekToken(); if (t == null) { @@ -988,6 +994,7 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser { return this.tokenStreamPointer= this.tokenStreamLength) { return null; @@ -995,6 +1002,7 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser { return this.tokenStream.get(this.tokenStreamPointer++); } + @Nullable private Token peekToken() { if (this.tokenStreamPointer >= this.tokenStreamLength) { return null; diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/standard/SpelCompiler.java b/spring-expression/src/main/java/org/springframework/expression/spel/standard/SpelCompiler.java index 9d29944c34..ff79a7fa54 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/standard/SpelCompiler.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/standard/SpelCompiler.java @@ -35,6 +35,7 @@ import org.springframework.expression.spel.CodeFlow; import org.springframework.expression.spel.CompiledExpression; import org.springframework.expression.spel.SpelParserConfiguration; import org.springframework.expression.spel.ast.SpelNodeImpl; +import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.util.ConcurrentReferenceHashMap; import org.springframework.util.ReflectionUtils; @@ -97,6 +98,7 @@ public class SpelCompiler implements Opcodes { * @return an instance of the class implementing the compiled expression, or null * if compilation is not possible */ + @Nullable public CompiledExpression compile(SpelNodeImpl expression) { if (expression.isCompilable()) { if (logger.isDebugEnabled()) { @@ -130,6 +132,7 @@ public class SpelCompiler implements Opcodes { * @return the expression call, or {@code null} if the decision was to opt out of * compilation during code generation */ + @Nullable private Class createExpressionClass(SpelNodeImpl expressionToCompile) { // Create class outline 'spel/ExNNN extends org.springframework.expression.spel.CompiledExpression' String clazzName = "spel/Ex" + getNextSuffix(); diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/standard/package-info.java b/spring-expression/src/main/java/org/springframework/expression/spel/standard/package-info.java index a7f7fd14f5..a33e8e3f66 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/standard/package-info.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/standard/package-info.java @@ -1,4 +1,7 @@ /** * SpEL's standard parser implementation. */ +@NonNullApi package org.springframework.expression.spel.standard; + +import org.springframework.lang.NonNullApi; diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectionHelper.java b/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectionHelper.java index e4a1613370..ef7843a90f 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectionHelper.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectionHelper.java @@ -26,6 +26,7 @@ import org.springframework.core.convert.TypeDescriptor; import org.springframework.expression.EvaluationException; import org.springframework.expression.TypeConverter; import org.springframework.expression.spel.SpelEvaluationException; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.MethodInvoker; @@ -50,6 +51,7 @@ public class ReflectionHelper { * @return a MatchInfo object indicating what kind of match it was, * or {@code null} if it was not a match */ + @Nullable static ArgumentsMatchInfo compareArguments( List expectedArgTypes, List suppliedArgTypes, TypeConverter typeConverter) { @@ -139,6 +141,7 @@ public class ReflectionHelper { * @return a MatchInfo object indicating what kind of match it was, * or {@code null} if it was not a match */ + @Nullable static ArgumentsMatchInfo compareArgumentsVarargs( List expectedArgTypes, List suppliedArgTypes, TypeConverter typeConverter) { @@ -257,8 +260,9 @@ public class ReflectionHelper { * @return {@code true} if some kind of conversion occurred on an argument * @throws EvaluationException if a problem occurs during conversion */ + @Nullable static boolean convertArguments(TypeConverter converter, Object[] arguments, Executable executable, - Integer varargsPosition) throws EvaluationException { + @Nullable Integer varargsPosition) throws EvaluationException { boolean conversionOccurred = false; if (varargsPosition == null) { diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectiveMethodExecutor.java b/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectiveMethodExecutor.java index b2798c3dda..1a038be186 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectiveMethodExecutor.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectiveMethodExecutor.java @@ -25,6 +25,7 @@ import org.springframework.expression.AccessException; import org.springframework.expression.EvaluationContext; import org.springframework.expression.MethodExecutor; import org.springframework.expression.TypedValue; +import org.springframework.lang.Nullable; import org.springframework.util.ReflectionUtils; /** @@ -75,6 +76,7 @@ public class ReflectiveMethodExecutor implements MethodExecutor { return this.publicDeclaringClass; } + @Nullable private Class discoverPublicClass(Method method, Class clazz) { if (Modifier.isPublic(clazz.getModifiers())) { try { diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectivePropertyAccessor.java b/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectivePropertyAccessor.java index 1841995d78..9be665ece2 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectivePropertyAccessor.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectivePropertyAccessor.java @@ -40,6 +40,7 @@ import org.springframework.expression.PropertyAccessor; import org.springframework.expression.TypedValue; import org.springframework.expression.spel.CodeFlow; import org.springframework.expression.spel.CompilablePropertyAccessor; +import org.springframework.lang.Nullable; import org.springframework.util.ReflectionUtils; import org.springframework.util.StringUtils; @@ -367,6 +368,7 @@ public class ReflectivePropertyAccessor implements PropertyAccessor { "set", clazz, mustBeStatic, 1, ANY_TYPES); } + @Nullable private Method findMethodForProperty(String[] methodSuffixes, String prefix, Class clazz, boolean mustBeStatic, int numberOfParams, Set> requiredReturnTypes) { @@ -427,6 +429,7 @@ public class ReflectivePropertyAccessor implements PropertyAccessor { /** * Find a field of a certain name on a specified class. */ + @Nullable protected Field findField(String name, Class clazz, boolean mustBeStatic) { Field[] fields = clazz.getFields(); for (Field field : fields) { diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/support/package-info.java b/spring-expression/src/main/java/org/springframework/expression/spel/support/package-info.java index d5503bc870..513c065672 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/support/package-info.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/support/package-info.java @@ -1,4 +1,7 @@ /** * SpEL's default implementations for various core abstractions. */ +@NonNullApi package org.springframework.expression.spel.support; + +import org.springframework.lang.NonNullApi; diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/config/DatabasePopulatorConfigUtils.java b/spring-jdbc/src/main/java/org/springframework/jdbc/config/DatabasePopulatorConfigUtils.java index 276b8bfa0c..5c32c678d7 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/config/DatabasePopulatorConfigUtils.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/config/DatabasePopulatorConfigUtils.java @@ -27,6 +27,7 @@ import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.support.ManagedList; import org.springframework.jdbc.datasource.init.CompositeDatabasePopulator; import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; +import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; import org.springframework.util.xml.DomUtils; @@ -82,6 +83,7 @@ class DatabasePopulatorConfigUtils { return builder.getBeanDefinition(); } + @Nullable private static String getSeparator(Element element, Element scriptElement) { String scriptSeparator = scriptElement.getAttribute("separator"); if (StringUtils.hasLength(scriptSeparator)) { diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/config/package-info.java b/spring-jdbc/src/main/java/org/springframework/jdbc/config/package-info.java index 26bc92c9c3..770d44e0a1 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/config/package-info.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/config/package-info.java @@ -1,4 +1,7 @@ /** * Defines the Spring JDBC configuration namespace. */ +@NonNullApi package org.springframework.jdbc.config; + +import org.springframework.lang.NonNullApi; diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/BeanPropertyRowMapper.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/BeanPropertyRowMapper.java index 51833133f1..c7f2b2eb49 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/BeanPropertyRowMapper.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/BeanPropertyRowMapper.java @@ -39,6 +39,7 @@ import org.springframework.core.convert.support.DefaultConversionService; import org.springframework.dao.DataRetrievalFailureException; import org.springframework.dao.InvalidDataAccessApiUsageException; import org.springframework.jdbc.support.JdbcUtils; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.StringUtils; @@ -192,7 +193,7 @@ public class BeanPropertyRowMapper implements RowMapper { * @since 4.3 * @see #initBeanWrapper(BeanWrapper) */ - public void setConversionService(ConversionService conversionService) { + public void setConversionService(@Nullable ConversionService conversionService) { this.conversionService = conversionService; } @@ -201,6 +202,7 @@ public class BeanPropertyRowMapper implements RowMapper { * or {@code null} if none. * @since 4.3 */ + @Nullable public ConversionService getConversionService() { return this.conversionService; } @@ -366,7 +368,7 @@ public class BeanPropertyRowMapper implements RowMapper { * @throws SQLException in case of extraction failure * @see org.springframework.jdbc.support.JdbcUtils#getResultSetValue(java.sql.ResultSet, int, Class) */ - protected Object getColumnValue(ResultSet rs, int index, PropertyDescriptor pd) throws SQLException { + protected Object getColumnValue(ResultSet rs, int index, @Nullable PropertyDescriptor pd) throws SQLException { return JdbcUtils.getResultSetValue(rs, index, pd.getPropertyType()); } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/CallableStatementCallback.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/CallableStatementCallback.java index 434e243737..166fbaefde 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/CallableStatementCallback.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/CallableStatementCallback.java @@ -20,6 +20,7 @@ import java.sql.CallableStatement; import java.sql.SQLException; import org.springframework.dao.DataAccessException; +import org.springframework.lang.Nullable; /** * Generic callback interface for code that operates on a CallableStatement. @@ -73,6 +74,7 @@ public interface CallableStatementCallback { * into a DataAccessException by a SQLExceptionTranslator * @throws DataAccessException in case of custom exceptions */ + @Nullable T doInCallableStatement(CallableStatement cs) throws SQLException, DataAccessException; } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/CallableStatementCreatorFactory.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/CallableStatementCreatorFactory.java index ffe32040d3..92b40555d0 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/CallableStatementCreatorFactory.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/CallableStatementCreatorFactory.java @@ -26,6 +26,7 @@ import java.util.List; import java.util.Map; import org.springframework.dao.InvalidDataAccessApiUsageException; +import org.springframework.lang.Nullable; /** * Helper class that efficiently creates multiple {@link CallableStatementCreator} @@ -102,7 +103,7 @@ public class CallableStatementCreatorFactory { * Return a new CallableStatementCreator instance given this parameters. * @param params list of parameters (may be {@code null}) */ - public CallableStatementCreator newCallableStatementCreator(Map params) { + public CallableStatementCreator newCallableStatementCreator(@Nullable Map params) { return new CallableStatementCreatorImpl(params != null ? params : new HashMap<>()); } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/ConnectionCallback.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/ConnectionCallback.java index 7c99bdc01a..8a0f50d290 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/ConnectionCallback.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/ConnectionCallback.java @@ -20,6 +20,7 @@ import java.sql.Connection; import java.sql.SQLException; import org.springframework.dao.DataAccessException; +import org.springframework.lang.Nullable; /** * Generic callback interface for code that operates on a JDBC Connection. @@ -62,6 +63,7 @@ public interface ConnectionCallback { * @see JdbcTemplate#queryForObject(String, Class) * @see JdbcTemplate#queryForRowSet(String) */ + @Nullable T doInConnection(Connection con) throws SQLException, DataAccessException; } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcOperations.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcOperations.java index 8f403c8f3d..c9d25bdfe6 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcOperations.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcOperations.java @@ -24,6 +24,7 @@ import org.springframework.dao.DataAccessException; import org.springframework.dao.IncorrectResultSizeDataAccessException; import org.springframework.jdbc.support.KeyHolder; import org.springframework.jdbc.support.rowset.SqlRowSet; +import org.springframework.lang.Nullable; /** * Interface specifying a basic set of JDBC operations. @@ -59,6 +60,7 @@ public interface JdbcOperations { * @return a result object returned by the action, or {@code null} * @throws DataAccessException if there is any problem */ + @Nullable T execute(ConnectionCallback action) throws DataAccessException; @@ -78,6 +80,7 @@ public interface JdbcOperations { * @return a result object returned by the action, or {@code null} * @throws DataAccessException if there is any problem */ + @Nullable T execute(StatementCallback action) throws DataAccessException; /** @@ -162,6 +165,7 @@ public interface JdbcOperations { * @throws DataAccessException if there is any problem executing the query * @see #queryForObject(String, Object[], Class) */ + @Nullable T queryForObject(String sql, Class requiredType) throws DataAccessException; /** @@ -288,6 +292,7 @@ public interface JdbcOperations { * @return a result object returned by the action, or {@code null} * @throws DataAccessException if there is any problem */ + @Nullable T execute(String sql, PreparedStatementCallback action) throws DataAccessException; /** @@ -315,7 +320,7 @@ public interface JdbcOperations { * @return an arbitrary result object, as returned by the ResultSetExtractor * @throws DataAccessException if there is any problem */ - T query(String sql, PreparedStatementSetter pss, ResultSetExtractor rse) throws DataAccessException; + T query(String sql, @Nullable PreparedStatementSetter pss, ResultSetExtractor rse) throws DataAccessException; /** * Query given SQL to create a prepared statement from SQL and a list @@ -360,7 +365,7 @@ public interface JdbcOperations { * @return an arbitrary result object, as returned by the ResultSetExtractor * @throws DataAccessException if the query fails */ - T query(String sql, ResultSetExtractor rse, Object... args) throws DataAccessException; + T query(String sql, ResultSetExtractor rse, @Nullable Object... args) throws DataAccessException; /** * Query using a prepared statement, reading the ResultSet on a per-row @@ -387,7 +392,7 @@ public interface JdbcOperations { * @param rch object that will extract results, one row at a time * @throws DataAccessException if the query fails */ - void query(String sql, PreparedStatementSetter pss, RowCallbackHandler rch) throws DataAccessException; + void query(String sql, @Nullable PreparedStatementSetter pss, RowCallbackHandler rch) throws DataAccessException; /** * Query given SQL to create a prepared statement from SQL and a list of @@ -429,7 +434,7 @@ public interface JdbcOperations { * only the argument value but also the SQL type and optionally the scale * @throws DataAccessException if the query fails */ - void query(String sql, RowCallbackHandler rch, Object... args) throws DataAccessException; + void query(String sql, RowCallbackHandler rch, @Nullable Object... args) throws DataAccessException; /** * Query using a prepared statement, mapping each row to a Java object @@ -457,7 +462,7 @@ public interface JdbcOperations { * @return the result List, containing mapped objects * @throws DataAccessException if the query fails */ - List query(String sql, PreparedStatementSetter pss, RowMapper rowMapper) throws DataAccessException; + List query(String sql, @Nullable PreparedStatementSetter pss, RowMapper rowMapper) throws DataAccessException; /** * Query given SQL to create a prepared statement from SQL and a list @@ -502,7 +507,7 @@ public interface JdbcOperations { * @return the result List, containing mapped objects * @throws DataAccessException if the query fails */ - List query(String sql, RowMapper rowMapper, Object... args) throws DataAccessException; + List query(String sql, RowMapper rowMapper, @Nullable Object... args) throws DataAccessException; /** * Query given SQL to create a prepared statement from SQL and a list @@ -554,7 +559,7 @@ public interface JdbcOperations { * return exactly one row * @throws DataAccessException if the query fails */ - T queryForObject(String sql, RowMapper rowMapper, Object... args) throws DataAccessException; + T queryForObject(String sql, RowMapper rowMapper, @Nullable Object... args) throws DataAccessException; /** * Query given SQL to create a prepared statement from SQL and a @@ -573,6 +578,7 @@ public interface JdbcOperations { * @see #queryForObject(String, Class) * @see java.sql.Types */ + @Nullable T queryForObject(String sql, Object[] args, int[] argTypes, Class requiredType) throws DataAccessException; @@ -593,6 +599,7 @@ public interface JdbcOperations { * @throws DataAccessException if the query fails * @see #queryForObject(String, Class) */ + @Nullable T queryForObject(String sql, Object[] args, Class requiredType) throws DataAccessException; /** @@ -612,7 +619,8 @@ public interface JdbcOperations { * @throws DataAccessException if the query fails * @see #queryForObject(String, Class) */ - T queryForObject(String sql, Class requiredType, Object... args) throws DataAccessException; + @Nullable + T queryForObject(String sql, Class requiredType, @Nullable Object... args) throws DataAccessException; /** * Query given SQL to create a prepared statement from SQL and a @@ -655,7 +663,7 @@ public interface JdbcOperations { * @see #queryForMap(String) * @see ColumnMapRowMapper */ - Map queryForMap(String sql, Object... args) throws DataAccessException; + Map queryForMap(String sql, @Nullable Object... args) throws DataAccessException; /** * Query given SQL to create a prepared statement from SQL and a @@ -712,7 +720,7 @@ public interface JdbcOperations { * @see #queryForList(String, Class) * @see SingleColumnRowMapper */ - List queryForList(String sql, Class elementType, Object... args) throws DataAccessException; + List queryForList(String sql, Class elementType, @Nullable Object... args) throws DataAccessException; /** * Query given SQL to create a prepared statement from SQL and a @@ -748,7 +756,7 @@ public interface JdbcOperations { * @throws DataAccessException if the query fails * @see #queryForList(String) */ - List> queryForList(String sql, Object... args) throws DataAccessException; + List> queryForList(String sql, @Nullable Object... args) throws DataAccessException; /** * Query given SQL to create a prepared statement from SQL and a @@ -794,7 +802,7 @@ public interface JdbcOperations { * @see SqlRowSetResultSetExtractor * @see javax.sql.rowset.CachedRowSet */ - SqlRowSet queryForRowSet(String sql, Object... args) throws DataAccessException; + SqlRowSet queryForRowSet(String sql, @Nullable Object... args) throws DataAccessException; /** * Issue a single SQL update operation (such as an insert, update or delete statement) @@ -834,7 +842,7 @@ public interface JdbcOperations { * @return the number of rows affected * @throws DataAccessException if there is any problem issuing the update */ - int update(String sql, PreparedStatementSetter pss) throws DataAccessException; + int update(String sql, @Nullable PreparedStatementSetter pss) throws DataAccessException; /** * Issue a single SQL update operation (such as an insert, update or delete statement) @@ -860,7 +868,7 @@ public interface JdbcOperations { * @return the number of rows affected * @throws DataAccessException if there is any problem issuing the update */ - int update(String sql, Object... args) throws DataAccessException; + int update(String sql, @Nullable Object... args) throws DataAccessException; /** * Issue multiple update statements on a single PreparedStatement, @@ -926,6 +934,7 @@ public interface JdbcOperations { * @return a result object returned by the action, or {@code null} * @throws DataAccessException if there is any problem */ + @Nullable T execute(CallableStatementCreator csc, CallableStatementCallback action) throws DataAccessException; /** @@ -941,6 +950,7 @@ public interface JdbcOperations { * @return a result object returned by the action, or {@code null} * @throws DataAccessException if there is any problem */ + @Nullable T execute(String callString, CallableStatementCallback action) throws DataAccessException; /** diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java index 73739eaf35..3ec3998315 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java @@ -35,6 +35,7 @@ import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; + import javax.sql.DataSource; import org.springframework.dao.DataAccessException; @@ -47,6 +48,7 @@ import org.springframework.jdbc.support.JdbcAccessor; import org.springframework.jdbc.support.JdbcUtils; import org.springframework.jdbc.support.KeyHolder; import org.springframework.jdbc.support.rowset.SqlRowSet; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.LinkedCaseInsensitiveMap; import org.springframework.util.StringUtils; @@ -1349,7 +1351,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { * May be {@code null}, in which case this method does nothing. * @throws SQLWarningException in case of an actual warning to be raised */ - protected void handleWarnings(SQLWarning warning) throws SQLWarningException { + protected void handleWarnings(@Nullable SQLWarning warning) throws SQLWarningException { if (warning != null) { throw new SQLWarningException("Warning not ignored", warning); } @@ -1361,6 +1363,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { * @return the SQL string, or {@code null} * @see SqlProvider */ + @Nullable private static String getSql(Object sqlProvider) { if (sqlProvider instanceof SqlProvider) { return ((SqlProvider) sqlProvider).getSql(); @@ -1385,6 +1388,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { } @Override + @Nullable public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { // Invocation on ConnectionProxy interface coming in... diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/ParameterMapper.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/ParameterMapper.java index 8198084ee2..0c7833ad8c 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/ParameterMapper.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/ParameterMapper.java @@ -20,6 +20,8 @@ import java.sql.Connection; import java.sql.SQLException; import java.util.Map; +import org.springframework.lang.Nullable; + /** * Implement this interface when parameters need to be customized based * on the connection. We might need to do this to make use of proprietary @@ -43,6 +45,7 @@ public interface ParameterMapper { * parameter values (that is, there's no need to catch SQLException) * @return Map of input parameters, keyed by name (never {@code null}) */ + @Nullable Map createMap(Connection con) throws SQLException; } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/PreparedStatementCallback.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/PreparedStatementCallback.java index 3db375c7b9..5025f7fc2d 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/PreparedStatementCallback.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/PreparedStatementCallback.java @@ -20,6 +20,7 @@ import java.sql.PreparedStatement; import java.sql.SQLException; import org.springframework.dao.DataAccessException; +import org.springframework.lang.Nullable; /** * Generic callback interface for code that operates on a PreparedStatement. @@ -72,6 +73,7 @@ public interface PreparedStatementCallback { * @see JdbcTemplate#queryForObject(String, Object[], Class) * @see JdbcTemplate#queryForList(String, Object[]) */ + @Nullable T doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException; } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/PreparedStatementCreatorFactory.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/PreparedStatementCreatorFactory.java index 22e59af455..72768bcbc7 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/PreparedStatementCreatorFactory.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/PreparedStatementCreatorFactory.java @@ -30,6 +30,7 @@ import java.util.List; import java.util.Set; import org.springframework.dao.InvalidDataAccessApiUsageException; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -135,7 +136,7 @@ public class PreparedStatementCreatorFactory { * Return a new PreparedStatementSetter for the given parameters. * @param params list of parameters (may be {@code null}) */ - public PreparedStatementSetter newPreparedStatementSetter(List params) { + public PreparedStatementSetter newPreparedStatementSetter(@Nullable List params) { return new PreparedStatementCreatorImpl(params != null ? params : Collections.emptyList()); } @@ -143,7 +144,7 @@ public class PreparedStatementCreatorFactory { * Return a new PreparedStatementSetter for the given parameters. * @param params the parameter array (may be {@code null}) */ - public PreparedStatementSetter newPreparedStatementSetter(Object[] params) { + public PreparedStatementSetter newPreparedStatementSetter(@Nullable Object[] params) { return new PreparedStatementCreatorImpl(params != null ? Arrays.asList(params) : Collections.emptyList()); } @@ -151,7 +152,7 @@ public class PreparedStatementCreatorFactory { * Return a new PreparedStatementCreator for the given parameters. * @param params list of parameters (may be {@code null}) */ - public PreparedStatementCreator newPreparedStatementCreator(List params) { + public PreparedStatementCreator newPreparedStatementCreator(@Nullable List params) { return new PreparedStatementCreatorImpl(params != null ? params : Collections.emptyList()); } @@ -159,7 +160,7 @@ public class PreparedStatementCreatorFactory { * Return a new PreparedStatementCreator for the given parameters. * @param params the parameter array (may be {@code null}) */ - public PreparedStatementCreator newPreparedStatementCreator(Object[] params) { + public PreparedStatementCreator newPreparedStatementCreator(@Nullable Object[] params) { return new PreparedStatementCreatorImpl(params != null ? Arrays.asList(params) : Collections.emptyList()); } @@ -169,7 +170,7 @@ public class PreparedStatementCreatorFactory { * the factory's, for example because of named parameter expanding) * @param params the parameter array (may be {@code null}) */ - public PreparedStatementCreator newPreparedStatementCreator(String sqlToUse, Object[] params) { + public PreparedStatementCreator newPreparedStatementCreator(String sqlToUse, @Nullable Object[] params) { return new PreparedStatementCreatorImpl( sqlToUse, params != null ? Arrays.asList(params) : Collections.emptyList()); } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/ResultSetExtractor.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/ResultSetExtractor.java index 7ada08f789..87ab2f31d5 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/ResultSetExtractor.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/ResultSetExtractor.java @@ -20,6 +20,7 @@ import java.sql.ResultSet; import java.sql.SQLException; import org.springframework.dao.DataAccessException; +import org.springframework.lang.Nullable; /** * Callback interface used by {@link JdbcTemplate}'s query methods. @@ -59,6 +60,7 @@ public interface ResultSetExtractor { * values or navigating (that is, there's no need to catch SQLException) * @throws DataAccessException in case of custom exceptions */ + @Nullable T extractData(ResultSet rs) throws SQLException, DataAccessException; } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/ResultSetSupportingSqlParameter.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/ResultSetSupportingSqlParameter.java index ca515b5bbc..5d56a100c9 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/ResultSetSupportingSqlParameter.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/ResultSetSupportingSqlParameter.java @@ -16,6 +16,8 @@ package org.springframework.jdbc.core; +import org.springframework.lang.Nullable; + /** * Common base class for ResultSet-supporting SqlParameters like * {@link SqlOutParameter} and {@link SqlReturnResultSet}. @@ -107,6 +109,7 @@ public class ResultSetSupportingSqlParameter extends SqlParameter { /** * Return the ResultSetExtractor held by this parameter, if any. */ + @Nullable public ResultSetExtractor getResultSetExtractor() { return this.resultSetExtractor; } @@ -114,6 +117,7 @@ public class ResultSetSupportingSqlParameter extends SqlParameter { /** * Return the RowCallbackHandler held by this parameter, if any. */ + @Nullable public RowCallbackHandler getRowCallbackHandler() { return this.rowCallbackHandler; } @@ -121,6 +125,7 @@ public class ResultSetSupportingSqlParameter extends SqlParameter { /** * Return the RowMapper held by this parameter, if any. */ + @Nullable public RowMapper getRowMapper() { return this.rowMapper; } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/SingleColumnRowMapper.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/SingleColumnRowMapper.java index 25456d9e92..b60e525786 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/SingleColumnRowMapper.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/SingleColumnRowMapper.java @@ -23,6 +23,7 @@ import java.sql.SQLException; import org.springframework.dao.TypeMismatchDataAccessException; import org.springframework.jdbc.IncorrectResultSetColumnCountException; import org.springframework.jdbc.support.JdbcUtils; +import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.util.NumberUtils; @@ -125,7 +126,7 @@ public class SingleColumnRowMapper implements RowMapper { * @see org.springframework.jdbc.support.JdbcUtils#getResultSetValue(java.sql.ResultSet, int, Class) * @see #getColumnValue(java.sql.ResultSet, int) */ - protected Object getColumnValue(ResultSet rs, int index, Class requiredType) throws SQLException { + protected Object getColumnValue(ResultSet rs, int index, @Nullable Class requiredType) throws SQLException { if (requiredType != null) { return JdbcUtils.getResultSetValue(rs, index, requiredType); } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/SqlOutParameter.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/SqlOutParameter.java index 0baba25d2f..2b164a0478 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/SqlOutParameter.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/SqlOutParameter.java @@ -16,6 +16,8 @@ package org.springframework.jdbc.core; +import org.springframework.lang.Nullable; + /** * Subclass of SqlParameter to represent an output parameter. * No additional properties: instanceof will be used to check @@ -111,6 +113,7 @@ public class SqlOutParameter extends ResultSetSupportingSqlParameter { /** * Return the custom return type, if any. */ + @Nullable public SqlReturnType getSqlReturnType() { return this.sqlReturnType; } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/SqlParameter.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/SqlParameter.java index 929b6c3960..850c13c431 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/SqlParameter.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/SqlParameter.java @@ -19,6 +19,7 @@ package org.springframework.jdbc.core; import java.util.LinkedList; import java.util.List; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -127,6 +128,7 @@ public class SqlParameter { /** * Return the name of the parameter, or {@code null} if anonymous. */ + @Nullable public String getName() { return this.name; } @@ -141,6 +143,7 @@ public class SqlParameter { /** * Return the type name of the parameter, if any. */ + @Nullable public String getTypeName() { return this.typeName; } @@ -148,6 +151,7 @@ public class SqlParameter { /** * Return the scale of the parameter, if any. */ + @Nullable public Integer getScale() { return this.scale; } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/SqlProvider.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/SqlProvider.java index 34b7dbb892..279f381474 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/SqlProvider.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/SqlProvider.java @@ -16,6 +16,8 @@ package org.springframework.jdbc.core; +import org.springframework.lang.Nullable; + /** * Interface to be implemented by objects that can provide SQL strings. * @@ -36,6 +38,7 @@ public interface SqlProvider { * typically the SQL used for creating statements. * @return the SQL string, or {@code null} */ + @Nullable String getSql(); } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/StatementCallback.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/StatementCallback.java index 7fdb710192..227886f99f 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/StatementCallback.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/StatementCallback.java @@ -20,6 +20,7 @@ import java.sql.SQLException; import java.sql.Statement; import org.springframework.dao.DataAccessException; +import org.springframework.lang.Nullable; /** * Generic callback interface for code that operates on a JDBC Statement. @@ -65,6 +66,7 @@ public interface StatementCallback { * @see JdbcTemplate#queryForObject(String, Class) * @see JdbcTemplate#queryForRowSet(String) */ + @Nullable T doInStatement(Statement stmt) throws SQLException, DataAccessException; } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/StatementCreatorUtils.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/StatementCreatorUtils.java index 91f593bc70..3182c6dfc8 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/StatementCreatorUtils.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/StatementCreatorUtils.java @@ -37,6 +37,7 @@ import org.apache.commons.logging.LogFactory; import org.springframework.core.SpringProperties; import org.springframework.jdbc.support.SqlValue; +import org.springframework.lang.Nullable; /** * Utility methods for PreparedStatementSetter/Creator and CallableStatementCreator @@ -111,6 +112,7 @@ public abstract class StatementCreatorUtils { * @param javaType the Java type to translate * @return the corresponding SQL type, or {@code null} if none found */ + @Nullable public static int javaTypeToSqlParameterType(Class javaType) { Integer sqlType = javaTypeToSqlTypeMap.get(javaType); if (sqlType != null) { @@ -422,7 +424,7 @@ public abstract class StatementCreatorUtils { * @see DisposableSqlTypeValue#cleanup() * @see org.springframework.jdbc.core.support.SqlLobValue#cleanup() */ - public static void cleanupParameters(Object... paramValues) { + public static void cleanupParameters(@Nullable Object... paramValues) { if (paramValues != null) { cleanupParameters(Arrays.asList(paramValues)); } @@ -435,7 +437,7 @@ public abstract class StatementCreatorUtils { * @see DisposableSqlTypeValue#cleanup() * @see org.springframework.jdbc.core.support.SqlLobValue#cleanup() */ - public static void cleanupParameters(Collection paramValues) { + public static void cleanupParameters(@Nullable Collection paramValues) { if (paramValues != null) { for (Object inValue : paramValues) { if (inValue instanceof DisposableSqlTypeValue) { diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/CallMetaDataProvider.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/CallMetaDataProvider.java index 2991c6d55c..fee434e247 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/CallMetaDataProvider.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/CallMetaDataProvider.java @@ -21,6 +21,7 @@ import java.sql.SQLException; import java.util.List; import org.springframework.jdbc.core.SqlParameter; +import org.springframework.lang.Nullable; /** * Interface specifying the API to be implemented by a class providing call metadata. @@ -52,25 +53,28 @@ public interface CallMetaDataProvider { * @see org.springframework.jdbc.core.simple.SimpleJdbcCall#withoutProcedureColumnMetaDataAccess() */ void initializeWithProcedureColumnMetaData( - DatabaseMetaData databaseMetaData, String catalogName, String schemaName, String procedureName) + DatabaseMetaData databaseMetaData, @Nullable String catalogName, @Nullable String schemaName, String procedureName) throws SQLException; /** * Provide any modification of the procedure name passed in to match the meta data currently used. * This could include altering the case. */ + @Nullable String procedureNameToUse(String procedureName); /** * Provide any modification of the catalog name passed in to match the meta data currently used. * This could include altering the case. */ + @Nullable String catalogNameToUse(String catalogName); /** * Provide any modification of the schema name passed in to match the meta data currently used. * This could include altering the case. */ + @Nullable String schemaNameToUse(String schemaName); /** @@ -78,6 +82,7 @@ public interface CallMetaDataProvider { * The returned value will be used for meta data lookups. This could include altering the case * used or providing a base catalog if none is provided. */ + @Nullable String metaDataCatalogNameToUse(String catalogName) ; /** @@ -85,6 +90,7 @@ public interface CallMetaDataProvider { * The returned value will be used for meta data lookups. This could include altering the case * used or providing a base schema if none is provided. */ + @Nullable String metaDataSchemaNameToUse(String schemaName) ; /** diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/TableMetaDataProvider.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/TableMetaDataProvider.java index 746fe515d0..92b5c9d723 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/TableMetaDataProvider.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/TableMetaDataProvider.java @@ -20,6 +20,8 @@ import java.sql.DatabaseMetaData; import java.sql.SQLException; import java.util.List; +import org.springframework.lang.Nullable; + /** * Interface specifying the API to be implemented by a class providing table metadata. * This is intended for internal use by the Simple JDBC classes. @@ -46,7 +48,7 @@ public interface TableMetaDataProvider { * @throws SQLException in case of initialization failure */ void initializeWithTableColumnMetaData( - DatabaseMetaData databaseMetaData, String catalogName, String schemaName, String tableName) + DatabaseMetaData databaseMetaData, @Nullable String catalogName, @Nullable String schemaName, String tableName) throws SQLException; /** @@ -99,6 +101,7 @@ public interface TableMetaDataProvider { /** * Get the simple query to retrieve a generated key */ + @Nullable String getSimpleQueryForGetGeneratedKey(String tableName, String keyColumnName); /** diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/package-info.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/package-info.java index 7ad1eaee19..41e1f0010b 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/package-info.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/package-info.java @@ -1,4 +1,7 @@ /** * Context metadata abstraction for the configuration and execution of a stored procedure call. */ +@NonNullApi package org.springframework.jdbc.core.metadata; + +import org.springframework.lang.NonNullApi; diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/MapSqlParameterSource.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/MapSqlParameterSource.java index 53dd6eca6f..88df516c58 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/MapSqlParameterSource.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/MapSqlParameterSource.java @@ -21,6 +21,7 @@ import java.util.LinkedHashMap; import java.util.Map; import org.springframework.jdbc.core.SqlParameterValue; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -69,7 +70,7 @@ public class MapSqlParameterSource extends AbstractSqlParameterSource { * Create a new MapSqlParameterSource based on a Map. * @param values a Map holding existing parameter values (can be {@code null}) */ - public MapSqlParameterSource(Map values) { + public MapSqlParameterSource(@Nullable Map values) { addValues(values); } @@ -128,7 +129,7 @@ public class MapSqlParameterSource extends AbstractSqlParameterSource { * @return a reference to this parameter source, * so it's possible to chain several calls together */ - public MapSqlParameterSource addValues(Map values) { + public MapSqlParameterSource addValues(@Nullable Map values) { if (values != null) { for (Map.Entry entry : values.entrySet()) { this.values.put(entry.getKey(), entry.getValue()); diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/NamedParameterJdbcOperations.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/NamedParameterJdbcOperations.java index 33adeed088..81b92a223b 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/NamedParameterJdbcOperations.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/NamedParameterJdbcOperations.java @@ -27,6 +27,7 @@ import org.springframework.jdbc.core.RowCallbackHandler; import org.springframework.jdbc.core.RowMapper; import org.springframework.jdbc.support.KeyHolder; import org.springframework.jdbc.support.rowset.SqlRowSet; +import org.springframework.lang.Nullable; /** * Interface specifying a basic set of JDBC operations allowing the use @@ -67,6 +68,7 @@ public interface NamedParameterJdbcOperations { * @return a result object returned by the action, or {@code null} * @throws DataAccessException if there is any problem */ + @Nullable T execute(String sql, SqlParameterSource paramSource, PreparedStatementCallback action) throws DataAccessException; @@ -85,6 +87,7 @@ public interface NamedParameterJdbcOperations { * @return a result object returned by the action, or {@code null} * @throws DataAccessException if there is any problem */ + @Nullable T execute(String sql, Map paramMap, PreparedStatementCallback action) throws DataAccessException; @@ -101,6 +104,7 @@ public interface NamedParameterJdbcOperations { * @return a result object returned by the action, or {@code null} * @throws DataAccessException if there is any problem */ + @Nullable T execute(String sql, PreparedStatementCallback action) throws DataAccessException; /** @@ -267,6 +271,7 @@ public interface NamedParameterJdbcOperations { * @throws org.springframework.dao.DataAccessException if the query fails * @see org.springframework.jdbc.core.JdbcTemplate#queryForObject(String, Class) */ + @Nullable T queryForObject(String sql, SqlParameterSource paramSource, Class requiredType) throws DataAccessException; @@ -286,6 +291,7 @@ public interface NamedParameterJdbcOperations { * @throws org.springframework.dao.DataAccessException if the query fails * @see org.springframework.jdbc.core.JdbcTemplate#queryForObject(String, Class) */ + @Nullable T queryForObject(String sql, Map paramMap, Class requiredType) throws DataAccessException; diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/NamedParameterUtils.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/NamedParameterUtils.java index 065a254bed..2d27c89d3a 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/NamedParameterUtils.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/NamedParameterUtils.java @@ -28,6 +28,7 @@ import java.util.Set; import org.springframework.dao.InvalidDataAccessApiUsageException; import org.springframework.jdbc.core.SqlParameter; import org.springframework.jdbc.core.SqlParameterValue; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -319,7 +320,7 @@ public abstract class NamedParameterUtils { * @return the array of values */ public static Object[] buildValueArray( - ParsedSql parsedSql, SqlParameterSource paramSource, List declaredParams) { + ParsedSql parsedSql, SqlParameterSource paramSource, @Nullable List declaredParams) { Object[] paramArray = new Object[parsedSql.getTotalParameterCount()]; if (parsedSql.getNamedParameterCount() > 0 && parsedSql.getUnnamedParameterCount() > 0) { @@ -352,6 +353,7 @@ public abstract class NamedParameterUtils { * @param paramIndex the index of the desired parameter * @return the declared SqlParameter, or {@code null} if none found */ + @Nullable private static SqlParameter findParameter(List declaredParams, String paramName, int paramIndex) { if (declaredParams != null) { // First pass: Look for named parameter match. diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/SqlParameterSource.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/SqlParameterSource.java index bdba8e4438..cd8e8cc519 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/SqlParameterSource.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/SqlParameterSource.java @@ -17,6 +17,7 @@ package org.springframework.jdbc.core.namedparam; import org.springframework.jdbc.support.JdbcUtils; +import org.springframework.lang.Nullable; /** * Interface that defines common functionality for objects that can @@ -79,6 +80,7 @@ public interface SqlParameterSource { * @return the type name of the specified parameter, * or {@code null} if not known */ + @Nullable String getTypeName(String paramName); } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/package-info.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/package-info.java index 50928e43b1..5ea4238dce 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/package-info.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/package-info.java @@ -10,4 +10,7 @@ * the {@code getJdbcOperations()} method of NamedParameterJdbcTemplate and * work with the returned classic template, or use a JdbcTemplate instance directly. */ +@NonNullApi package org.springframework.jdbc.core.namedparam; + +import org.springframework.lang.NonNullApi; diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/package-info.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/package-info.java index 2a769e0335..5591e5419e 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/package-info.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/package-info.java @@ -2,4 +2,7 @@ * Provides the core JDBC framework, based on JdbcTemplate * and its associated callback interfaces and helper objects. */ +@NonNullApi package org.springframework.jdbc.core; + +import org.springframework.lang.NonNullApi; diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/package-info.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/package-info.java index d9403a2c9b..c70d9d97d2 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/package-info.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/package-info.java @@ -5,4 +5,7 @@ * of database metadata provided by the JDBC driver to simplify the application code. Much of the * parameter specification becomes unnecessary since it can be looked up in the metadata. */ +@NonNullApi package org.springframework.jdbc.core.simple; + +import org.springframework.lang.NonNullApi; diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/support/package-info.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/support/package-info.java index 8f3b9a2a06..44b556fee4 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/support/package-info.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/support/package-info.java @@ -2,4 +2,7 @@ * Classes supporting the {@code org.springframework.jdbc.core} package. * Contains a DAO base class for JdbcTemplate usage. */ +@NonNullApi package org.springframework.jdbc.core.support; + +import org.springframework.lang.NonNullApi; diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/AbstractDriverBasedDataSource.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/AbstractDriverBasedDataSource.java index 11558ddb11..e9d721dc5c 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/AbstractDriverBasedDataSource.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/AbstractDriverBasedDataSource.java @@ -20,6 +20,7 @@ import java.sql.Connection; import java.sql.SQLException; import java.util.Properties; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -105,6 +106,7 @@ public abstract class AbstractDriverBasedDataSource extends AbstractDataSource { * Return the database catalog to be applied to each Connection, if any. * @since 4.3.2 */ + @Nullable public String getCatalog() { return this.catalog; } @@ -122,6 +124,7 @@ public abstract class AbstractDriverBasedDataSource extends AbstractDataSource { * Return the database schema to be applied to each Connection, if any. * @since 4.3.2 */ + @Nullable public String getSchema() { return this.schema; } @@ -141,6 +144,7 @@ public abstract class AbstractDriverBasedDataSource extends AbstractDataSource { /** * Return the connection properties to be passed to the Driver, if any. */ + @Nullable public Properties getConnectionProperties() { return this.connectionProperties; } @@ -178,7 +182,7 @@ public abstract class AbstractDriverBasedDataSource extends AbstractDataSource { * @throws SQLException in case of failure * @see java.sql.Driver#connect(String, java.util.Properties) */ - protected Connection getConnectionFromDriver(String username, String password) throws SQLException { + protected Connection getConnectionFromDriver(@Nullable String username, @Nullable String password) throws SQLException { Properties mergedProps = new Properties(); Properties connProps = getConnectionProperties(); if (connProps != null) { diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/ConnectionHolder.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/ConnectionHolder.java index 26dcbda8cc..82bfe63e93 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/ConnectionHolder.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/ConnectionHolder.java @@ -20,6 +20,7 @@ import java.sql.Connection; import java.sql.SQLException; import java.sql.Savepoint; +import org.springframework.lang.Nullable; import org.springframework.transaction.support.ResourceHolderSupport; import org.springframework.util.Assert; @@ -125,7 +126,7 @@ public class ConnectionHolder extends ResourceHolderSupport { *

    Used for releasing the Connection on suspend (with a {@code null} * argument) and setting a fresh Connection on resume. */ - protected void setConnection(Connection connection) { + protected void setConnection(@Nullable Connection connection) { if (this.currentConnection != null) { this.connectionHandle.releaseConnection(this.currentConnection); this.currentConnection = null; diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/DataSourceUtils.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/DataSourceUtils.java index eb766badbb..89030b3988 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/DataSourceUtils.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/DataSourceUtils.java @@ -19,12 +19,14 @@ package org.springframework.jdbc.datasource; import java.sql.Connection; import java.sql.SQLException; import java.sql.Statement; + import javax.sql.DataSource; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.jdbc.CannotGetJdbcConnectionException; +import org.springframework.lang.Nullable; import org.springframework.transaction.TransactionDefinition; import org.springframework.transaction.support.TransactionSynchronizationAdapter; import org.springframework.transaction.support.TransactionSynchronizationManager; @@ -141,6 +143,7 @@ public abstract class DataSourceUtils { * @throws SQLException if thrown by JDBC methods * @see #resetConnectionAfterTransaction */ + @Nullable public static Integer prepareConnectionForTransaction(Connection con, TransactionDefinition definition) throws SQLException { @@ -192,7 +195,7 @@ public abstract class DataSourceUtils { * @param previousIsolationLevel the isolation level to restore, if any * @see #prepareConnectionForTransaction */ - public static void resetConnectionAfterTransaction(Connection con, Integer previousIsolationLevel) { + public static void resetConnectionAfterTransaction(Connection con, @Nullable Integer previousIsolationLevel) { Assert.notNull(con, "No Connection specified"); try { // Reset transaction isolation to previous value, if changed for the transaction. @@ -225,7 +228,7 @@ public abstract class DataSourceUtils { * (may be {@code null}) * @return whether the Connection is transactional */ - public static boolean isConnectionTransactional(Connection con, DataSource dataSource) { + public static boolean isConnectionTransactional(Connection con, @Nullable DataSource dataSource) { if (dataSource == null) { return false; } @@ -277,7 +280,7 @@ public abstract class DataSourceUtils { * (may be {@code null}) * @see #getConnection */ - public static void releaseConnection(Connection con, DataSource dataSource) { + public static void releaseConnection(Connection con, @Nullable DataSource dataSource) { try { doReleaseConnection(con, dataSource); } @@ -300,7 +303,7 @@ public abstract class DataSourceUtils { * @throws SQLException if thrown by JDBC methods * @see #doGetConnection */ - public static void doReleaseConnection(Connection con, DataSource dataSource) throws SQLException { + public static void doReleaseConnection(Connection con, @Nullable DataSource dataSource) throws SQLException { if (con == null) { return; } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/IsolationLevelDataSourceAdapter.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/IsolationLevelDataSourceAdapter.java index 30f64d47a2..8feb983a7e 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/IsolationLevelDataSourceAdapter.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/IsolationLevelDataSourceAdapter.java @@ -20,6 +20,7 @@ import java.sql.Connection; import java.sql.SQLException; import org.springframework.core.Constants; +import org.springframework.lang.Nullable; import org.springframework.transaction.TransactionDefinition; import org.springframework.transaction.support.DefaultTransactionDefinition; import org.springframework.transaction.support.TransactionSynchronizationManager; @@ -111,6 +112,7 @@ public class IsolationLevelDataSourceAdapter extends UserCredentialsDataSourceAd * Return the statically specified isolation level, * or {@code null} if none. */ + @Nullable protected Integer getIsolationLevel() { return this.isolationLevel; } @@ -143,6 +145,7 @@ public class IsolationLevelDataSourceAdapter extends UserCredentialsDataSourceAd * @see org.springframework.transaction.support.TransactionSynchronizationManager#getCurrentTransactionIsolationLevel() * @see #setIsolationLevel */ + @Nullable protected Integer getCurrentIsolationLevel() { Integer isolationLevelToUse = TransactionSynchronizationManager.getCurrentTransactionIsolationLevel(); if (isolationLevelToUse == null) { diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/LazyConnectionDataSourceProxy.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/LazyConnectionDataSourceProxy.java index 8396d1be5b..1ab0613b0b 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/LazyConnectionDataSourceProxy.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/LazyConnectionDataSourceProxy.java @@ -28,6 +28,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.core.Constants; +import org.springframework.lang.Nullable; /** * Proxy for a target DataSource, fetching actual JDBC Connections lazily, @@ -271,6 +272,7 @@ public class LazyConnectionDataSourceProxy extends DelegatingDataSource { } @Override + @Nullable public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { // Invocation on ConnectionProxy interface coming in... diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/SingleConnectionDataSource.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/SingleConnectionDataSource.java index b7bd8df0df..613441014b 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/SingleConnectionDataSource.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/SingleConnectionDataSource.java @@ -24,6 +24,7 @@ import java.sql.Connection; import java.sql.SQLException; import org.springframework.beans.factory.DisposableBean; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; @@ -146,6 +147,7 @@ public class SingleConnectionDataSource extends DriverManagerDataSource implemen * Return whether the returned Connection's "autoCommit" setting should be overridden. * @return the "autoCommit" value, or {@code null} if none to be applied */ + @Nullable protected Boolean getAutoCommitValue() { return this.autoCommit; } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/TransactionAwareDataSourceProxy.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/TransactionAwareDataSourceProxy.java index f90b9bdb42..78269ba5a8 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/TransactionAwareDataSourceProxy.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/TransactionAwareDataSourceProxy.java @@ -25,6 +25,7 @@ import java.sql.SQLException; import java.sql.Statement; import javax.sql.DataSource; +import org.springframework.lang.Nullable; import org.springframework.transaction.support.TransactionSynchronizationManager; import org.springframework.util.Assert; @@ -171,6 +172,7 @@ public class TransactionAwareDataSourceProxy extends DelegatingDataSource { } @Override + @Nullable public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { // Invocation on ConnectionProxy interface coming in... diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/WebSphereDataSourceAdapter.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/WebSphereDataSourceAdapter.java index 42b47d85c0..31d7a80a3d 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/WebSphereDataSourceAdapter.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/WebSphereDataSourceAdapter.java @@ -19,11 +19,13 @@ package org.springframework.jdbc.datasource; import java.lang.reflect.Method; import java.sql.Connection; import java.sql.SQLException; + import javax.sql.DataSource; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.lang.Nullable; import org.springframework.util.ReflectionUtils; import org.springframework.util.StringUtils; @@ -157,7 +159,7 @@ public class WebSphereDataSourceAdapter extends IsolationLevelDataSourceAdapter * @see com.ibm.websphere.rsadapter.JDBCConnectionSpec */ protected Object createConnectionSpec( - Integer isolationLevel, Boolean readOnlyFlag, String username, String password) throws SQLException { + @Nullable Integer isolationLevel, @Nullable Boolean readOnlyFlag, @Nullable String username, @Nullable String password) throws SQLException { Object connSpec = ReflectionUtils.invokeJdbcMethod(this.newJdbcConnSpecMethod, null); if (isolationLevel != null) { diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseFactory.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseFactory.java index baf30e4052..fa3ad1a688 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseFactory.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseFactory.java @@ -21,6 +21,7 @@ import java.sql.Connection; import java.sql.SQLException; import java.util.UUID; import java.util.logging.Logger; + import javax.sql.DataSource; import org.apache.commons.logging.Log; @@ -29,6 +30,7 @@ import org.apache.commons.logging.LogFactory; import org.springframework.jdbc.datasource.SimpleDriverDataSource; import org.springframework.jdbc.datasource.init.DatabasePopulator; import org.springframework.jdbc.datasource.init.DatabasePopulatorUtils; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -234,6 +236,7 @@ public class EmbeddedDatabaseFactory { * or if the database has been shut down. Subclasses may call this method to * access the {@code DataSource} instance directly. */ + @Nullable protected final DataSource getDataSource() { return this.dataSource; } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/package-info.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/package-info.java index 4cb074c575..18e1a70337 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/package-info.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/package-info.java @@ -1,4 +1,7 @@ /** * Provides extensible support for creating embedded database instances. */ +@NonNullApi package org.springframework.jdbc.datasource.embedded; + +import org.springframework.lang.NonNullApi; diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/ResourceDatabasePopulator.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/ResourceDatabasePopulator.java index 43d51decb9..192fd96e83 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/ResourceDatabasePopulator.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/ResourceDatabasePopulator.java @@ -20,10 +20,12 @@ import java.sql.Connection; import java.util.ArrayList; import java.util.Arrays; import java.util.List; + import javax.sql.DataSource; import org.springframework.core.io.Resource; import org.springframework.core.io.support.EncodedResource; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -102,7 +104,7 @@ public class ResourceDatabasePopulator implements DatabasePopulator { * @since 4.0.3 */ public ResourceDatabasePopulator(boolean continueOnError, boolean ignoreFailedDrops, - String sqlScriptEncoding, Resource... scripts) { + @Nullable String sqlScriptEncoding, Resource... scripts) { this(scripts); this.continueOnError = continueOnError; @@ -152,7 +154,7 @@ public class ResourceDatabasePopulator implements DatabasePopulator { * or empty to indicate platform encoding * @see #addScript(Resource) */ - public void setSqlScriptEncoding(String sqlScriptEncoding) { + public void setSqlScriptEncoding(@Nullable String sqlScriptEncoding) { this.sqlScriptEncoding = StringUtils.hasText(sqlScriptEncoding) ? sqlScriptEncoding : null; } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/package-info.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/package-info.java index ff831a91f8..ffe5057737 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/package-info.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/package-info.java @@ -1,4 +1,7 @@ /** * Provides extensible support for initializing databases through scripts. */ +@NonNullApi package org.springframework.jdbc.datasource.init; + +import org.springframework.lang.NonNullApi; diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/lookup/MapDataSourceLookup.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/lookup/MapDataSourceLookup.java index 24cfdfbe78..49aa557fa5 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/lookup/MapDataSourceLookup.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/lookup/MapDataSourceLookup.java @@ -19,8 +19,10 @@ package org.springframework.jdbc.datasource.lookup; import java.util.Collections; import java.util.HashMap; import java.util.Map; + import javax.sql.DataSource; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -71,7 +73,7 @@ public class MapDataSourceLookup implements DataSourceLookup { * call effectively has no effect. * @param dataSources said {@link Map} of {@link DataSource DataSources} */ - public void setDataSources(Map dataSources) { + public void setDataSources(@Nullable Map dataSources) { if (dataSources != null) { this.dataSources.putAll(dataSources); } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/lookup/package-info.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/lookup/package-info.java index e7f32d33e4..2c20a49426 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/lookup/package-info.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/lookup/package-info.java @@ -1,4 +1,7 @@ /** * Provides a strategy for looking up JDBC DataSources by name. */ +@NonNullApi package org.springframework.jdbc.datasource.lookup; + +import org.springframework.lang.NonNullApi; diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/package-info.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/package-info.java index 9dce44a2c4..6dce266ab4 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/package-info.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/package-info.java @@ -3,4 +3,7 @@ * a PlatformTransactionManager for a single DataSource, * and various simple DataSource implementations. */ +@NonNullApi package org.springframework.jdbc.datasource; + +import org.springframework.lang.NonNullApi; diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/object/MappingSqlQueryWithParameters.java b/spring-jdbc/src/main/java/org/springframework/jdbc/object/MappingSqlQueryWithParameters.java index ae0b5fc32b..f6fd55637b 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/object/MappingSqlQueryWithParameters.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/object/MappingSqlQueryWithParameters.java @@ -19,9 +19,11 @@ package org.springframework.jdbc.object; import java.sql.ResultSet; import java.sql.SQLException; import java.util.Map; + import javax.sql.DataSource; import org.springframework.jdbc.core.RowMapper; +import org.springframework.lang.Nullable; /** * Reusable RDBMS query in which concrete subclasses must implement @@ -89,7 +91,7 @@ public abstract class MappingSqlQueryWithParameters extends SqlQuery { * Subclasses can simply not catch SQLExceptions, relying on the * framework to clean up. */ - protected abstract T mapRow(ResultSet rs, int rowNum, Object[] parameters, Map context) + protected abstract T mapRow(ResultSet rs, int rowNum, @Nullable Object[] parameters, @Nullable Map context) throws SQLException; diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/object/RdbmsOperation.java b/spring-jdbc/src/main/java/org/springframework/jdbc/object/RdbmsOperation.java index a1d71e1ff6..557fbd6eb2 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/object/RdbmsOperation.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/object/RdbmsOperation.java @@ -23,6 +23,7 @@ import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.Map; + import javax.sql.DataSource; import org.apache.commons.logging.Log; @@ -32,6 +33,7 @@ import org.springframework.beans.factory.InitializingBean; import org.springframework.dao.InvalidDataAccessApiUsageException; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.SqlParameter; +import org.springframework.lang.Nullable; /** * An "RDBMS operation" is a multi-threaded, reusable object representing a query, @@ -376,7 +378,7 @@ public abstract class RdbmsOperation implements InitializingBean { * @param parameters parameters supplied (may be {@code null}) * @throws InvalidDataAccessApiUsageException if the parameters are invalid */ - protected void validateParameters(Object[] parameters) throws InvalidDataAccessApiUsageException { + protected void validateParameters(@Nullable Object[] parameters) throws InvalidDataAccessApiUsageException { checkCompiled(); int declaredInParameters = 0; for (SqlParameter param : this.declaredParameters) { @@ -399,7 +401,7 @@ public abstract class RdbmsOperation implements InitializingBean { * @param parameters parameter Map supplied. May be {@code null}. * @throws InvalidDataAccessApiUsageException if the parameters are invalid */ - protected void validateNamedParameters(Map parameters) throws InvalidDataAccessApiUsageException { + protected void validateNamedParameters(@Nullable Map parameters) throws InvalidDataAccessApiUsageException { checkCompiled(); Map paramsToUse = (parameters != null ? parameters : Collections. emptyMap()); int declaredInParameters = 0; diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/object/SqlCall.java b/spring-jdbc/src/main/java/org/springframework/jdbc/object/SqlCall.java index 6420802d3f..3196499910 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/object/SqlCall.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/object/SqlCall.java @@ -18,12 +18,14 @@ package org.springframework.jdbc.object; import java.util.List; import java.util.Map; + import javax.sql.DataSource; import org.springframework.jdbc.core.CallableStatementCreator; import org.springframework.jdbc.core.CallableStatementCreatorFactory; import org.springframework.jdbc.core.ParameterMapper; import org.springframework.jdbc.core.SqlParameter; +import org.springframework.lang.Nullable; /** * RdbmsOperation using a JdbcTemplate and representing a SQL-based @@ -180,7 +182,7 @@ public abstract class SqlCall extends RdbmsOperation { * with this parameters. * @param inParams parameters. May be {@code null}. */ - protected CallableStatementCreator newCallableStatementCreator(Map inParams) { + protected CallableStatementCreator newCallableStatementCreator(@Nullable Map inParams) { return this.callableStatementFactory.newCallableStatementCreator(inParams); } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/object/SqlOperation.java b/spring-jdbc/src/main/java/org/springframework/jdbc/object/SqlOperation.java index bc85ae180b..01cad6dd31 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/object/SqlOperation.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/object/SqlOperation.java @@ -21,6 +21,7 @@ import org.springframework.jdbc.core.PreparedStatementCreatorFactory; import org.springframework.jdbc.core.PreparedStatementSetter; import org.springframework.jdbc.core.namedparam.NamedParameterUtils; import org.springframework.jdbc.core.namedparam.ParsedSql; +import org.springframework.lang.Nullable; /** * Operation object representing a SQL-based operation such as a query or update, @@ -91,7 +92,7 @@ public abstract class SqlOperation extends RdbmsOperation { * with the given parameters. * @param params the parameter array (may be {@code null}) */ - protected final PreparedStatementSetter newPreparedStatementSetter(Object[] params) { + protected final PreparedStatementSetter newPreparedStatementSetter(@Nullable Object[] params) { return this.preparedStatementFactory.newPreparedStatementSetter(params); } @@ -100,7 +101,7 @@ public abstract class SqlOperation extends RdbmsOperation { * with the given parameters. * @param params the parameter array (may be {@code null}) */ - protected final PreparedStatementCreator newPreparedStatementCreator(Object[] params) { + protected final PreparedStatementCreator newPreparedStatementCreator(@Nullable Object[] params) { return this.preparedStatementFactory.newPreparedStatementCreator(params); } @@ -111,7 +112,7 @@ public abstract class SqlOperation extends RdbmsOperation { * the factory's, for example because of named parameter expanding) * @param params the parameter array (may be {@code null}) */ - protected final PreparedStatementCreator newPreparedStatementCreator(String sqlToUse, Object[] params) { + protected final PreparedStatementCreator newPreparedStatementCreator(String sqlToUse, @Nullable Object[] params) { return this.preparedStatementFactory.newPreparedStatementCreator(sqlToUse, params); } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/object/SqlQuery.java b/spring-jdbc/src/main/java/org/springframework/jdbc/object/SqlQuery.java index 93bbc68077..2c02e55cdb 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/object/SqlQuery.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/object/SqlQuery.java @@ -18,6 +18,7 @@ package org.springframework.jdbc.object; import java.util.List; import java.util.Map; + import javax.sql.DataSource; import org.springframework.dao.DataAccessException; @@ -26,6 +27,7 @@ import org.springframework.jdbc.core.RowMapper; import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; import org.springframework.jdbc.core.namedparam.NamedParameterUtils; import org.springframework.jdbc.core.namedparam.ParsedSql; +import org.springframework.lang.Nullable; /** * Reusable operation object representing a SQL query. @@ -247,6 +249,7 @@ public abstract class SqlQuery extends SqlOperation { * choose to treat this as an error and throw an exception. * @see org.springframework.dao.support.DataAccessUtils#singleResult */ + @Nullable public T findObject(Object[] params, Map context) throws DataAccessException { List results = execute(params, context); return DataAccessUtils.singleResult(results); @@ -357,6 +360,6 @@ public abstract class SqlQuery extends SqlOperation { * but it can be useful for creating the objects of the result list. * @see #execute */ - protected abstract RowMapper newRowMapper(Object[] parameters, Map context); + protected abstract RowMapper newRowMapper(@Nullable Object[] parameters, Map context); } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/object/StoredProcedure.java b/spring-jdbc/src/main/java/org/springframework/jdbc/object/StoredProcedure.java index 30e08b29e7..8a71bf511b 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/object/StoredProcedure.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/object/StoredProcedure.java @@ -18,6 +18,7 @@ package org.springframework.jdbc.object; import java.util.HashMap; import java.util.Map; + import javax.sql.DataSource; import org.springframework.dao.DataAccessException; @@ -25,6 +26,7 @@ import org.springframework.dao.InvalidDataAccessApiUsageException; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.ParameterMapper; import org.springframework.jdbc.core.SqlParameter; +import org.springframework.lang.Nullable; /** * Superclass for object abstractions of RDBMS stored procedures. @@ -109,7 +111,7 @@ public abstract class StoredProcedure extends SqlCall { * Output parameters will appear here, with their values after the * stored procedure has been called. */ - public Map execute(Object... inParams) { + public Map execute(@Nullable Object... inParams) { Map paramsToUse = new HashMap<>(); validateParameters(inParams); int i = 0; @@ -137,7 +139,7 @@ public abstract class StoredProcedure extends SqlCall { * Output parameters will appear here, with their values after the * stored procedure has been called. */ - public Map execute(Map inParams) throws DataAccessException { + public Map execute(@Nullable Map inParams) throws DataAccessException { validateParameters(inParams.values().toArray()); return getJdbcTemplate().call(newCallableStatementCreator(inParams), getDeclaredParameters()); } @@ -158,7 +160,7 @@ public abstract class StoredProcedure extends SqlCall { * Output parameters will appear here, with their values after the * stored procedure has been called. */ - public Map execute(ParameterMapper inParamMapper) throws DataAccessException { + public Map execute(@Nullable ParameterMapper inParamMapper) throws DataAccessException { checkCompiled(); return getJdbcTemplate().call(newCallableStatementCreator(inParamMapper), getDeclaredParameters()); } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/object/UpdatableSqlQuery.java b/spring-jdbc/src/main/java/org/springframework/jdbc/object/UpdatableSqlQuery.java index 081504f94f..326b2eaf18 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/object/UpdatableSqlQuery.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/object/UpdatableSqlQuery.java @@ -19,9 +19,11 @@ package org.springframework.jdbc.object; import java.sql.ResultSet; import java.sql.SQLException; import java.util.Map; + import javax.sql.DataSource; import org.springframework.jdbc.core.RowMapper; +import org.springframework.lang.Nullable; /** * Reusable RDBMS query in which concrete subclasses must implement @@ -78,7 +80,7 @@ public abstract class UpdatableSqlQuery extends SqlQuery { * Subclasses can simply not catch SQLExceptions, relying on the * framework to clean up. */ - protected abstract T updateRow(ResultSet rs, int rowNum, Map context) throws SQLException; + protected abstract T updateRow(ResultSet rs, int rowNum, @Nullable Map context) throws SQLException; /** diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/object/package-info.java b/spring-jdbc/src/main/java/org/springframework/jdbc/object/package-info.java index 6bbe5166b9..8a511307bf 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/object/package-info.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/object/package-info.java @@ -14,4 +14,7 @@ * Expert One-On-One J2EE Design and Development * by Rod Johnson (Wrox, 2002). */ +@NonNullApi package org.springframework.jdbc.object; + +import org.springframework.lang.NonNullApi; diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/package-info.java b/spring-jdbc/src/main/java/org/springframework/jdbc/package-info.java index 1a05b52b1b..ec5e65fd6a 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/package-info.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/package-info.java @@ -17,4 +17,7 @@ * Expert One-On-One J2EE Design and Development * by Rod Johnson (Wrox, 2002). */ +@NonNullApi package org.springframework.jdbc; + +import org.springframework.lang.NonNullApi; diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/AbstractFallbackSQLExceptionTranslator.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/AbstractFallbackSQLExceptionTranslator.java index 6e4c548eab..639f374f0a 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/AbstractFallbackSQLExceptionTranslator.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/AbstractFallbackSQLExceptionTranslator.java @@ -23,6 +23,7 @@ import org.apache.commons.logging.LogFactory; import org.springframework.dao.DataAccessException; import org.springframework.jdbc.UncategorizedSQLException; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -51,6 +52,7 @@ public abstract class AbstractFallbackSQLExceptionTranslator implements SQLExcep /** * Return the fallback exception translator, if any. */ + @Nullable public SQLExceptionTranslator getFallbackTranslator() { return this.fallbackTranslator; } @@ -95,7 +97,8 @@ public abstract class AbstractFallbackSQLExceptionTranslator implements SQLExcep * @return the DataAccessException, wrapping the {@code SQLException}; * or {@code null} if no exception match found */ - protected abstract DataAccessException doTranslate(String task, String sql, SQLException ex); + @Nullable + protected abstract DataAccessException doTranslate(String task, @Nullable String sql, SQLException ex); /** @@ -107,7 +110,7 @@ public abstract class AbstractFallbackSQLExceptionTranslator implements SQLExcep * @param ex the offending {@code SQLException} * @return the message {@code String} to use */ - protected String buildMessage(String task, String sql, SQLException ex) { + protected String buildMessage(String task, @Nullable String sql, SQLException ex) { return task + "; SQL [" + sql + "]; " + ex.getMessage(); } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/CustomSQLExceptionTranslatorRegistry.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/CustomSQLExceptionTranslatorRegistry.java index 19801eb592..928f310273 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/CustomSQLExceptionTranslatorRegistry.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/CustomSQLExceptionTranslatorRegistry.java @@ -22,6 +22,8 @@ import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.lang.Nullable; + /** * Registry for custom {@link org.springframework.jdbc.support.SQLExceptionTranslator} instances associated with * specific databases allowing for overriding translation based on values contained in the configuration file @@ -86,6 +88,7 @@ public class CustomSQLExceptionTranslatorRegistry { * @param dbName the database name * @return the custom translator, or {@code null} if none found */ + @Nullable public SQLExceptionTranslator findTranslatorForDatabase(String dbName) { return this.translatorMap.get(dbName); } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/JdbcUtils.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/JdbcUtils.java index 0ed787eaf7..4b7640df90 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/JdbcUtils.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/JdbcUtils.java @@ -29,6 +29,7 @@ import java.sql.SQLException; import java.sql.SQLFeatureNotSupportedException; import java.sql.Statement; import java.sql.Types; + import javax.sql.DataSource; import org.apache.commons.logging.Log; @@ -36,6 +37,7 @@ import org.apache.commons.logging.LogFactory; import org.springframework.jdbc.CannotGetJdbcConnectionException; import org.springframework.jdbc.datasource.DataSourceUtils; +import org.springframework.lang.Nullable; import org.springframework.util.NumberUtils; /** @@ -61,7 +63,7 @@ public abstract class JdbcUtils { * This is useful for typical finally blocks in manual JDBC code. * @param con the JDBC Connection to close (may be {@code null}) */ - public static void closeConnection(Connection con) { + public static void closeConnection(@Nullable Connection con) { if (con != null) { try { con.close(); @@ -81,7 +83,7 @@ public abstract class JdbcUtils { * This is useful for typical finally blocks in manual JDBC code. * @param stmt the JDBC Statement to close (may be {@code null}) */ - public static void closeStatement(Statement stmt) { + public static void closeStatement(@Nullable Statement stmt) { if (stmt != null) { try { stmt.close(); @@ -101,7 +103,7 @@ public abstract class JdbcUtils { * This is useful for typical finally blocks in manual JDBC code. * @param rs the JDBC ResultSet to close (may be {@code null}) */ - public static void closeResultSet(ResultSet rs) { + public static void closeResultSet(@Nullable ResultSet rs) { if (rs != null) { try { rs.close(); @@ -131,7 +133,7 @@ public abstract class JdbcUtils { * @throws SQLException if thrown by the JDBC API * @see #getResultSetValue(ResultSet, int) */ - public static Object getResultSetValue(ResultSet rs, int index, Class requiredType) throws SQLException { + public static Object getResultSetValue(ResultSet rs, int index, @Nullable Class requiredType) throws SQLException { if (requiredType == null) { return getResultSetValue(rs, index); } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/KeyHolder.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/KeyHolder.java index b917ecb95d..e71725bd10 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/KeyHolder.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/KeyHolder.java @@ -20,6 +20,7 @@ import java.util.List; import java.util.Map; import org.springframework.dao.InvalidDataAccessApiUsageException; +import org.springframework.lang.Nullable; /** * Interface for retrieving keys, typically used for auto-generated keys @@ -54,6 +55,7 @@ public interface KeyHolder { * @return the generated key * @throws InvalidDataAccessApiUsageException if multiple keys are encountered. */ + @Nullable Number getKey() throws InvalidDataAccessApiUsageException; /** @@ -63,6 +65,7 @@ public interface KeyHolder { * @return the Map of generated keys * @throws InvalidDataAccessApiUsageException if keys for multiple rows are encountered */ + @Nullable Map getKeys() throws InvalidDataAccessApiUsageException; /** diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/SQLErrorCodeSQLExceptionTranslator.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/SQLErrorCodeSQLExceptionTranslator.java index d9afb8837f..77b54ba5ce 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/SQLErrorCodeSQLExceptionTranslator.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/SQLErrorCodeSQLExceptionTranslator.java @@ -20,6 +20,7 @@ import java.lang.reflect.Constructor; import java.sql.BatchUpdateException; import java.sql.SQLException; import java.util.Arrays; + import javax.sql.DataSource; import org.springframework.dao.CannotAcquireLockException; @@ -33,6 +34,7 @@ import org.springframework.dao.PermissionDeniedDataAccessException; import org.springframework.dao.TransientDataAccessResourceException; import org.springframework.jdbc.BadSqlGrammarException; import org.springframework.jdbc.InvalidResultSetAccessException; +import org.springframework.lang.Nullable; /** * Implementation of {@link SQLExceptionTranslator} that analyzes vendor-specific error codes. @@ -295,7 +297,7 @@ public class SQLErrorCodeSQLExceptionTranslator extends AbstractFallbackSQLExcep * as a nested root cause. This implementation always returns null, meaning that * the translator always falls back to the default error codes. */ - protected DataAccessException customTranslate(String task, String sql, SQLException sqlEx) { + protected DataAccessException customTranslate(String task, @Nullable String sql, SQLException sqlEx) { return null; } @@ -313,7 +315,7 @@ public class SQLErrorCodeSQLExceptionTranslator extends AbstractFallbackSQLExcep * @see CustomSQLErrorCodesTranslation#setExceptionClass */ protected DataAccessException createCustomException( - String task, String sql, SQLException sqlEx, Class exceptionClass) { + String task, @Nullable String sql, SQLException sqlEx, Class exceptionClass) { // find appropriate constructor try { diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/SQLErrorCodesFactory.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/SQLErrorCodesFactory.java index 476c1915e1..f5a433740f 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/SQLErrorCodesFactory.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/SQLErrorCodesFactory.java @@ -18,6 +18,7 @@ package org.springframework.jdbc.support; import java.util.Collections; import java.util.Map; + import javax.sql.DataSource; import org.apache.commons.logging.Log; @@ -28,6 +29,7 @@ import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ConcurrentReferenceHashMap; import org.springframework.util.PatternMatchUtils; @@ -145,6 +147,7 @@ public class SQLErrorCodesFactory { * @return the resource, or {@code null} if the resource wasn't found * @see #getInstance */ + @Nullable protected Resource loadResource(String path) { return new ClassPathResource(path, getClass().getClassLoader()); } @@ -255,6 +258,7 @@ public class SQLErrorCodesFactory { * @since 4.3.5 * @see #registerDatabase(DataSource, String) */ + @Nullable public SQLErrorCodes unregisterDatabase(DataSource dataSource) { return this.dataSourceCache.remove(dataSource); } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/SQLExceptionTranslator.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/SQLExceptionTranslator.java index 193b1e1b1f..082e856c0e 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/SQLExceptionTranslator.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/SQLExceptionTranslator.java @@ -19,6 +19,7 @@ package org.springframework.jdbc.support; import java.sql.SQLException; import org.springframework.dao.DataAccessException; +import org.springframework.lang.Nullable; /** * Strategy interface for translating between {@link SQLException SQLExceptions} @@ -50,6 +51,7 @@ public interface SQLExceptionTranslator { * @return the DataAccessException, wrapping the {@code SQLException} * @see org.springframework.dao.DataAccessException#getRootCause() */ - DataAccessException translate(String task, String sql, SQLException ex); + @Nullable + DataAccessException translate(String task, @Nullable String sql, SQLException ex); } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/lob/LobCreator.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/lob/LobCreator.java index 2a93708979..77d9352650 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/lob/LobCreator.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/lob/LobCreator.java @@ -22,6 +22,8 @@ import java.io.Reader; import java.sql.PreparedStatement; import java.sql.SQLException; +import org.springframework.lang.Nullable; + /** * Interface that abstracts potentially database-specific creation of large binary * fields and large text fields. Does not work with {@code java.sql.Blob} @@ -68,7 +70,7 @@ public interface LobCreator extends Closeable { * @throws SQLException if thrown by JDBC methods * @see java.sql.PreparedStatement#setBytes */ - void setBlobAsBytes(PreparedStatement ps, int paramIndex, byte[] content) + void setBlobAsBytes(PreparedStatement ps, int paramIndex, @Nullable byte[] content) throws SQLException; /** @@ -82,7 +84,7 @@ public interface LobCreator extends Closeable { * @see java.sql.PreparedStatement#setBinaryStream */ void setBlobAsBinaryStream( - PreparedStatement ps, int paramIndex, InputStream contentStream, int contentLength) + PreparedStatement ps, int paramIndex, @Nullable InputStream contentStream, int contentLength) throws SQLException; /** @@ -95,7 +97,7 @@ public interface LobCreator extends Closeable { * @throws SQLException if thrown by JDBC methods * @see java.sql.PreparedStatement#setBytes */ - void setClobAsString(PreparedStatement ps, int paramIndex, String content) + void setClobAsString(PreparedStatement ps, int paramIndex, @Nullable String content) throws SQLException; /** @@ -109,7 +111,7 @@ public interface LobCreator extends Closeable { * @see java.sql.PreparedStatement#setAsciiStream */ void setClobAsAsciiStream( - PreparedStatement ps, int paramIndex, InputStream asciiStream, int contentLength) + PreparedStatement ps, int paramIndex, @Nullable InputStream asciiStream, int contentLength) throws SQLException; /** @@ -123,7 +125,7 @@ public interface LobCreator extends Closeable { * @see java.sql.PreparedStatement#setCharacterStream */ void setClobAsCharacterStream( - PreparedStatement ps, int paramIndex, Reader characterStream, int contentLength) + PreparedStatement ps, int paramIndex, @Nullable Reader characterStream, int contentLength) throws SQLException; /** diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/lob/LobHandler.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/lob/LobHandler.java index 83b4367d5c..0aef08ef1c 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/lob/LobHandler.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/lob/LobHandler.java @@ -21,6 +21,8 @@ import java.io.Reader; import java.sql.ResultSet; import java.sql.SQLException; +import org.springframework.lang.Nullable; + /** * Abstraction for handling large binary fields and large text fields in * specific databases, no matter if represented as simple types or Large OBjects. @@ -83,6 +85,7 @@ public interface LobHandler { * @throws SQLException if thrown by JDBC methods * @see java.sql.ResultSet#getBytes */ + @Nullable byte[] getBlobAsBytes(ResultSet rs, String columnName) throws SQLException; /** @@ -95,6 +98,7 @@ public interface LobHandler { * @throws SQLException if thrown by JDBC methods * @see java.sql.ResultSet#getBytes */ + @Nullable byte[] getBlobAsBytes(ResultSet rs, int columnIndex) throws SQLException; /** @@ -107,6 +111,7 @@ public interface LobHandler { * @throws SQLException if thrown by JDBC methods * @see java.sql.ResultSet#getBinaryStream */ + @Nullable InputStream getBlobAsBinaryStream(ResultSet rs, String columnName) throws SQLException; /** @@ -119,6 +124,7 @@ public interface LobHandler { * @throws SQLException if thrown by JDBC methods * @see java.sql.ResultSet#getBinaryStream */ + @Nullable InputStream getBlobAsBinaryStream(ResultSet rs, int columnIndex) throws SQLException; /** @@ -131,6 +137,7 @@ public interface LobHandler { * @throws SQLException if thrown by JDBC methods * @see java.sql.ResultSet#getString */ + @Nullable String getClobAsString(ResultSet rs, String columnName) throws SQLException; /** @@ -143,6 +150,7 @@ public interface LobHandler { * @throws SQLException if thrown by JDBC methods * @see java.sql.ResultSet#getString */ + @Nullable String getClobAsString(ResultSet rs, int columnIndex) throws SQLException; /** @@ -155,6 +163,7 @@ public interface LobHandler { * @throws SQLException if thrown by JDBC methods * @see java.sql.ResultSet#getAsciiStream */ + @Nullable InputStream getClobAsAsciiStream(ResultSet rs, String columnName) throws SQLException; /** @@ -167,6 +176,7 @@ public interface LobHandler { * @throws SQLException if thrown by JDBC methods * @see java.sql.ResultSet#getAsciiStream */ + @Nullable InputStream getClobAsAsciiStream(ResultSet rs, int columnIndex) throws SQLException; /** diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/lob/package-info.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/lob/package-info.java index 4ae1cfe995..6b2fa41698 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/lob/package-info.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/lob/package-info.java @@ -2,4 +2,7 @@ * Provides a strategy interface for Large OBject handling, * as well as a customizable default implementation. */ +@NonNullApi package org.springframework.jdbc.support.lob; + +import org.springframework.lang.NonNullApi; diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/package-info.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/package-info.java index ecd758ee01..6814d37a59 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/package-info.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/package-info.java @@ -6,4 +6,7 @@ *

    Can be used independently, for example in custom JDBC access code, * or in JDBC-based O/R mapping layers. */ +@NonNullApi package org.springframework.jdbc.support; + +import org.springframework.lang.NonNullApi; diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/rowset/package-info.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/rowset/package-info.java index b3d8f6c986..4d18ce41d7 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/rowset/package-info.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/rowset/package-info.java @@ -2,4 +2,7 @@ * Provides a convenient holder for disconnected result sets. * Supported by JdbcTemplate, but can be used independently too. */ +@NonNullApi package org.springframework.jdbc.support.rowset; + +import org.springframework.lang.NonNullApi; diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/xml/SqlXmlHandler.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/xml/SqlXmlHandler.java index 320a3bd977..c557bb9fb4 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/xml/SqlXmlHandler.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/xml/SqlXmlHandler.java @@ -20,11 +20,14 @@ import java.io.InputStream; import java.io.Reader; import java.sql.ResultSet; import java.sql.SQLException; + import javax.xml.transform.Result; import javax.xml.transform.Source; import org.w3c.dom.Document; +import org.springframework.lang.Nullable; + /** * Abstraction for handling XML fields in specific databases. Its main purpose * is to isolate database-specific handling of XML stored in the database. @@ -61,6 +64,7 @@ public interface SqlXmlHandler { * @see java.sql.ResultSet#getString * @see java.sql.ResultSet#getSQLXML */ + @Nullable String getXmlAsString(ResultSet rs, String columnName) throws SQLException; /** @@ -75,6 +79,7 @@ public interface SqlXmlHandler { * @see java.sql.ResultSet#getString * @see java.sql.ResultSet#getSQLXML */ + @Nullable String getXmlAsString(ResultSet rs, int columnIndex) throws SQLException; /** @@ -89,6 +94,7 @@ public interface SqlXmlHandler { * @see java.sql.ResultSet#getSQLXML * @see java.sql.SQLXML#getBinaryStream */ + @Nullable InputStream getXmlAsBinaryStream(ResultSet rs, String columnName) throws SQLException; /** @@ -103,6 +109,7 @@ public interface SqlXmlHandler { * @see java.sql.ResultSet#getSQLXML * @see java.sql.SQLXML#getBinaryStream */ + @Nullable InputStream getXmlAsBinaryStream(ResultSet rs, int columnIndex) throws SQLException; /** @@ -117,6 +124,7 @@ public interface SqlXmlHandler { * @see java.sql.ResultSet#getSQLXML * @see java.sql.SQLXML#getCharacterStream */ + @Nullable Reader getXmlAsCharacterStream(ResultSet rs, String columnName) throws SQLException; /** @@ -131,6 +139,7 @@ public interface SqlXmlHandler { * @see java.sql.ResultSet#getSQLXML * @see java.sql.SQLXML#getCharacterStream */ + @Nullable Reader getXmlAsCharacterStream(ResultSet rs, int columnIndex) throws SQLException; /** @@ -146,6 +155,7 @@ public interface SqlXmlHandler { * @see java.sql.ResultSet#getSQLXML * @see java.sql.SQLXML#getSource */ + @Nullable Source getXmlAsSource(ResultSet rs, String columnName, Class sourceClass) throws SQLException; /** @@ -161,6 +171,7 @@ public interface SqlXmlHandler { * @see java.sql.ResultSet#getSQLXML * @see java.sql.SQLXML#getSource */ + @Nullable Source getXmlAsSource(ResultSet rs, int columnIndex, Class sourceClass) throws SQLException; diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/xml/SqlXmlObjectMappingHandler.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/xml/SqlXmlObjectMappingHandler.java index 6e55f1ec88..1f8d4f7418 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/xml/SqlXmlObjectMappingHandler.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/xml/SqlXmlObjectMappingHandler.java @@ -19,6 +19,8 @@ package org.springframework.jdbc.support.xml; import java.sql.ResultSet; import java.sql.SQLException; +import org.springframework.lang.Nullable; + /** * Abstraction for handling XML object mapping to fields in a database. * @@ -43,6 +45,7 @@ public interface SqlXmlObjectMappingHandler extends SqlXmlHandler { * @throws java.sql.SQLException if thrown by JDBC methods * @see java.sql.ResultSet#getSQLXML */ + @Nullable Object getXmlAsObject(ResultSet rs, String columnName) throws SQLException; /** @@ -55,6 +58,7 @@ public interface SqlXmlObjectMappingHandler extends SqlXmlHandler { * @throws java.sql.SQLException if thrown by JDBC methods * @see java.sql.ResultSet#getSQLXML */ + @Nullable Object getXmlAsObject(ResultSet rs, int columnIndex) throws SQLException; /** diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/xml/package-info.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/xml/package-info.java index a6e46df0bf..14bfdee577 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/xml/package-info.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/xml/package-info.java @@ -1,4 +1,7 @@ /** * Abstraction for handling fields of SQLXML data type. */ +@NonNullApi package org.springframework.jdbc.support.xml; + +import org.springframework.lang.NonNullApi; diff --git a/spring-jdbc/src/main/kotlin/org/springframework/jdbc/core/JdbcOperationsExtensions.kt b/spring-jdbc/src/main/kotlin/org/springframework/jdbc/core/JdbcOperationsExtensions.kt index 9b2fb62c60..d28fcf6a70 100644 --- a/spring-jdbc/src/main/kotlin/org/springframework/jdbc/core/JdbcOperationsExtensions.kt +++ b/spring-jdbc/src/main/kotlin/org/springframework/jdbc/core/JdbcOperationsExtensions.kt @@ -26,7 +26,7 @@ import kotlin.reflect.KClass * @author Mario Arias * @since 5.0 */ -fun JdbcOperations.queryForObject(sql: String, elementType: KClass): T = queryForObject(sql, elementType.java) +fun JdbcOperations.queryForObject(sql: String, elementType: KClass): T? = queryForObject(sql, elementType.java) /** * Extension for [JdbcOperations.queryForObject] providing a `queryForObject("...")` variant @@ -34,7 +34,7 @@ fun JdbcOperations.queryForObject(sql: String, elementType: KClass) * @author Mario Arias * @since 5.0 */ -inline fun JdbcOperations.queryForObject(sql: String): T = queryForObject(sql, T::class.java) +inline fun JdbcOperations.queryForObject(sql: String): T? = queryForObject(sql, T::class.java) /** * Extensions for [JdbcOperations.queryForObject] providing a RowMapper-like function variant: `queryForObject("...", arg1, argN){ rs, i -> }`. @@ -51,7 +51,7 @@ fun JdbcOperations.queryForObject(sql: String, vararg args: Any, funct * @author Mario Arias * @since 5.0 */ -fun JdbcOperations.queryForObject(sql: String, args: Array, argTypes: IntArray, requiredType: KClass): T = +fun JdbcOperations.queryForObject(sql: String, args: Array, argTypes: IntArray, requiredType: KClass): T? = queryForObject(sql, args, argTypes, requiredType.java) /** @@ -60,7 +60,7 @@ fun JdbcOperations.queryForObject(sql: String, args: Array, a * @author Mario Arias * @since 5.0 */ -inline fun JdbcOperations.queryForObject(sql: String, args: Array, argTypes: IntArray): T = +inline fun JdbcOperations.queryForObject(sql: String, args: Array, argTypes: IntArray): T? = queryForObject(sql, args, argTypes, T::class.java) /** @@ -69,7 +69,7 @@ inline fun JdbcOperations.queryForObject(sql: String, args: Ar * @author Mario Arias * @since 5.0 */ -fun JdbcOperations.queryForObject(sql: String, args: Array, requiredType: KClass): T = +fun JdbcOperations.queryForObject(sql: String, args: Array, requiredType: KClass): T? = queryForObject(sql, args, requiredType.java) /** @@ -78,7 +78,7 @@ fun JdbcOperations.queryForObject(sql: String, args: Array, r * @author Mario Arias * @since 5.0 */ -inline fun JdbcOperations.queryForObject(sql: String, args: Array): T = +inline fun JdbcOperations.queryForObject(sql: String, args: Array): T? = queryForObject(sql, args, T::class.java) /** @@ -87,7 +87,7 @@ inline fun JdbcOperations.queryForObject(sql: String, args: Ar * @author Mario Arias * @since 5.0 */ -fun JdbcOperations.queryForObject(sql: String, requiredType: KClass, vararg args: Any): T = +fun JdbcOperations.queryForObject(sql: String, requiredType: KClass, vararg args: Any): T? = queryForObject(sql, requiredType.java, *args) diff --git a/spring-jdbc/src/test/kotlin/org/springframework/jdbc/core/JdbcOperationsExtensionsTests.kt b/spring-jdbc/src/test/kotlin/org/springframework/jdbc/core/JdbcOperationsExtensionsTests.kt index 9b9718844f..9f7cb441e9 100644 --- a/spring-jdbc/src/test/kotlin/org/springframework/jdbc/core/JdbcOperationsExtensionsTests.kt +++ b/spring-jdbc/src/test/kotlin/org/springframework/jdbc/core/JdbcOperationsExtensionsTests.kt @@ -82,7 +82,7 @@ class JdbcOperationsExtensionsTests { @Test fun `queryForObject with reified type`() { - val i: Int = template.queryForObject("select age from customer where id = 3") + val i: Int? = template.queryForObject("select age from customer where id = 3") assertEquals(22, i) } @@ -103,7 +103,7 @@ class JdbcOperationsExtensionsTests { @Test fun `queryForObject with reified type and argTypes`() { - val i: Int = template.queryForObject("select age from customer where id = ?", arrayOf(3), + val i: Int? = template.queryForObject("select age from customer where id = ?", arrayOf(3), intArrayOf(JDBCType.INTEGER.vendorTypeNumber)) assertEquals(22, i) } @@ -116,7 +116,7 @@ class JdbcOperationsExtensionsTests { @Test fun `queryForObject with reified type and args`() { - val i: Int = template.queryForObject("select age from customer where id = ?", arrayOf(3)) + val i: Int? = template.queryForObject("select age from customer where id = ?", arrayOf(3)) assertEquals(22, i) } diff --git a/spring-jms/src/main/java/org/springframework/jms/JmsException.java b/spring-jms/src/main/java/org/springframework/jms/JmsException.java index b2d3a6f442..5449776d56 100644 --- a/spring-jms/src/main/java/org/springframework/jms/JmsException.java +++ b/spring-jms/src/main/java/org/springframework/jms/JmsException.java @@ -19,6 +19,7 @@ package org.springframework.jms; import javax.jms.JMSException; import org.springframework.core.NestedRuntimeException; +import org.springframework.lang.Nullable; /** * Base class for exception thrown by the framework whenever it @@ -67,6 +68,7 @@ public abstract class JmsException extends NestedRuntimeException { * @return a string specifying the vendor-specific error code if the * root cause is an instance of JMSException, or {@code null} */ + @Nullable public String getErrorCode() { Throwable cause = getCause(); if (cause instanceof JMSException) { diff --git a/spring-jms/src/main/java/org/springframework/jms/annotation/package-info.java b/spring-jms/src/main/java/org/springframework/jms/annotation/package-info.java index 1255e309af..665ecd621a 100644 --- a/spring-jms/src/main/java/org/springframework/jms/annotation/package-info.java +++ b/spring-jms/src/main/java/org/springframework/jms/annotation/package-info.java @@ -1,4 +1,7 @@ /** * Annotations and support classes for declarative JMS listener endpoints. */ +@NonNullApi package org.springframework.jms.annotation; + +import org.springframework.lang.NonNullApi; diff --git a/spring-jms/src/main/java/org/springframework/jms/config/AbstractJmsListenerEndpoint.java b/spring-jms/src/main/java/org/springframework/jms/config/AbstractJmsListenerEndpoint.java index 21ae508db8..dcdef2aaea 100644 --- a/spring-jms/src/main/java/org/springframework/jms/config/AbstractJmsListenerEndpoint.java +++ b/spring-jms/src/main/java/org/springframework/jms/config/AbstractJmsListenerEndpoint.java @@ -22,6 +22,7 @@ import org.springframework.jms.listener.AbstractMessageListenerContainer; import org.springframework.jms.listener.MessageListenerContainer; import org.springframework.jms.listener.endpoint.JmsActivationSpecConfig; import org.springframework.jms.listener.endpoint.JmsMessageEndpointManager; +import org.springframework.lang.Nullable; /** * Base model for a JMS listener endpoint @@ -64,6 +65,7 @@ public abstract class AbstractJmsListenerEndpoint implements JmsListenerEndpoint /** * Return the name of the destination for this endpoint. */ + @Nullable public String getDestination() { return this.destination; } @@ -78,6 +80,7 @@ public abstract class AbstractJmsListenerEndpoint implements JmsListenerEndpoint /** * Return the name for the durable subscription, if any. */ + @Nullable public String getSubscription() { return this.subscription; } @@ -93,6 +96,7 @@ public abstract class AbstractJmsListenerEndpoint implements JmsListenerEndpoint /** * Return the JMS message selector expression, if any. */ + @Nullable public String getSelector() { return this.selector; } @@ -111,6 +115,7 @@ public abstract class AbstractJmsListenerEndpoint implements JmsListenerEndpoint /** * Return the concurrency for the listener, if any. */ + @Nullable public String getConcurrency() { return this.concurrency; } diff --git a/spring-jms/src/main/java/org/springframework/jms/config/AbstractListenerContainerParser.java b/spring-jms/src/main/java/org/springframework/jms/config/AbstractListenerContainerParser.java index f2d33d3023..62f41cf880 100644 --- a/spring-jms/src/main/java/org/springframework/jms/config/AbstractListenerContainerParser.java +++ b/spring-jms/src/main/java/org/springframework/jms/config/AbstractListenerContainerParser.java @@ -32,6 +32,7 @@ import org.springframework.beans.factory.parsing.CompositeComponentDefinition; import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.beans.factory.xml.BeanDefinitionParser; import org.springframework.beans.factory.xml.ParserContext; +import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; /** @@ -313,6 +314,7 @@ abstract class AbstractListenerContainerParser implements BeanDefinitionParser { * Create the {@link BeanDefinition} for the container factory using the specified * shared property values. */ + @Nullable protected abstract RootBeanDefinition createContainerFactory(String factoryId, Element containerEle, ParserContext parserContext, PropertyValues commonContainerProperties, PropertyValues specificContainerProperties); @@ -323,6 +325,7 @@ abstract class AbstractListenerContainerParser implements BeanDefinitionParser { PropertyValues commonContainerProperties, PropertyValues specificContainerProperties); + @Nullable protected Integer parseAcknowledgeMode(Element ele, ParserContext parserContext) { String acknowledge = ele.getAttribute(ACKNOWLEDGE_ATTRIBUTE); if (StringUtils.hasText(acknowledge)) { diff --git a/spring-jms/src/main/java/org/springframework/jms/config/JmsListenerEndpointRegistrar.java b/spring-jms/src/main/java/org/springframework/jms/config/JmsListenerEndpointRegistrar.java index 49d5eaf94e..a836bf2404 100644 --- a/spring-jms/src/main/java/org/springframework/jms/config/JmsListenerEndpointRegistrar.java +++ b/spring-jms/src/main/java/org/springframework/jms/config/JmsListenerEndpointRegistrar.java @@ -23,6 +23,7 @@ import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.lang.Nullable; import org.springframework.messaging.handler.annotation.support.DefaultMessageHandlerMethodFactory; import org.springframework.messaging.handler.annotation.support.MessageHandlerMethodFactory; import org.springframework.util.Assert; @@ -65,6 +66,7 @@ public class JmsListenerEndpointRegistrar implements BeanFactoryAware, Initializ * Return the {@link JmsListenerEndpointRegistry} instance for this * registrar, may be {@code null}. */ + @Nullable public JmsListenerEndpointRegistry getEndpointRegistry() { return this.endpointRegistry; } @@ -84,6 +86,7 @@ public class JmsListenerEndpointRegistrar implements BeanFactoryAware, Initializ /** * Return the custom {@link MessageHandlerMethodFactory} to use, if any. */ + @Nullable public MessageHandlerMethodFactory getMessageHandlerMethodFactory() { return this.messageHandlerMethodFactory; } @@ -164,7 +167,7 @@ public class JmsListenerEndpointRegistrar implements BeanFactoryAware, Initializ *

    The {@code factory} may be {@code null} if the default factory has to be * used for that endpoint. */ - public void registerEndpoint(JmsListenerEndpoint endpoint, JmsListenerContainerFactory factory) { + public void registerEndpoint(JmsListenerEndpoint endpoint, @Nullable JmsListenerContainerFactory factory) { Assert.notNull(endpoint, "Endpoint must be set"); Assert.hasText(endpoint.getId(), "Endpoint id must be set"); diff --git a/spring-jms/src/main/java/org/springframework/jms/config/JmsListenerEndpointRegistry.java b/spring-jms/src/main/java/org/springframework/jms/config/JmsListenerEndpointRegistry.java index f6d798c8dd..2b3897ec7e 100644 --- a/spring-jms/src/main/java/org/springframework/jms/config/JmsListenerEndpointRegistry.java +++ b/spring-jms/src/main/java/org/springframework/jms/config/JmsListenerEndpointRegistry.java @@ -35,6 +35,7 @@ import org.springframework.context.ApplicationListener; import org.springframework.context.SmartLifecycle; import org.springframework.context.event.ContextRefreshedEvent; import org.springframework.jms.listener.MessageListenerContainer; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -93,6 +94,7 @@ public class JmsListenerEndpointRegistry implements DisposableBean, SmartLifecyc * @see JmsListenerEndpoint#getId() * @see #getListenerContainerIds() */ + @Nullable public MessageListenerContainer getListenerContainer(String id) { Assert.notNull(id, "Container identifier must not be null"); return this.listenerContainers.get(id); diff --git a/spring-jms/src/main/java/org/springframework/jms/config/MethodJmsListenerEndpoint.java b/spring-jms/src/main/java/org/springframework/jms/config/MethodJmsListenerEndpoint.java index 21eda3484d..e90d7b7b4d 100644 --- a/spring-jms/src/main/java/org/springframework/jms/config/MethodJmsListenerEndpoint.java +++ b/spring-jms/src/main/java/org/springframework/jms/config/MethodJmsListenerEndpoint.java @@ -31,6 +31,7 @@ import org.springframework.jms.listener.adapter.MessagingMessageListenerAdapter; import org.springframework.jms.support.QosSettings; import org.springframework.jms.support.converter.MessageConverter; import org.springframework.jms.support.destination.DestinationResolver; +import org.springframework.lang.Nullable; import org.springframework.messaging.handler.annotation.SendTo; import org.springframework.messaging.handler.annotation.support.MessageHandlerMethodFactory; import org.springframework.messaging.handler.invocation.InvocableHandlerMethod; @@ -124,7 +125,7 @@ public class MethodJmsListenerEndpoint extends AbstractJmsListenerEndpoint imple * Set the {@link BeanFactory} to use to resolve expressions (may be {@code null}). */ @Override - public void setBeanFactory(BeanFactory beanFactory) { + public void setBeanFactory(@Nullable BeanFactory beanFactory) { if (this.embeddedValueResolver == null && beanFactory instanceof ConfigurableBeanFactory) { this.embeddedValueResolver = new EmbeddedValueResolver((ConfigurableBeanFactory) beanFactory); } @@ -174,6 +175,7 @@ public class MethodJmsListenerEndpoint extends AbstractJmsListenerEndpoint imple /** * Return the default response destination, if any. */ + @Nullable protected String getDefaultResponseDestination() { Method specificMethod = getMostSpecificMethod(); SendTo ann = getSendTo(specificMethod); diff --git a/spring-jms/src/main/java/org/springframework/jms/config/package-info.java b/spring-jms/src/main/java/org/springframework/jms/config/package-info.java index e9b696d3cb..9ef34e73c4 100644 --- a/spring-jms/src/main/java/org/springframework/jms/config/package-info.java +++ b/spring-jms/src/main/java/org/springframework/jms/config/package-info.java @@ -2,4 +2,7 @@ * Support package for declarative messaging configuration, * with Java configuration and XML schema support. */ +@NonNullApi package org.springframework.jms.config; + +import org.springframework.lang.NonNullApi; diff --git a/spring-jms/src/main/java/org/springframework/jms/connection/CachingConnectionFactory.java b/spring-jms/src/main/java/org/springframework/jms/connection/CachingConnectionFactory.java index ff70aef60c..06337af798 100644 --- a/spring-jms/src/main/java/org/springframework/jms/connection/CachingConnectionFactory.java +++ b/spring-jms/src/main/java/org/springframework/jms/connection/CachingConnectionFactory.java @@ -39,6 +39,7 @@ import javax.jms.TemporaryTopic; import javax.jms.Topic; import javax.jms.TopicSession; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; @@ -278,6 +279,7 @@ public class CachingConnectionFactory extends SingleConnectionFactory { } @Override + @Nullable public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { String methodName = method.getName(); if (methodName.equals("equals")) { diff --git a/spring-jms/src/main/java/org/springframework/jms/connection/ConnectionFactoryUtils.java b/spring-jms/src/main/java/org/springframework/jms/connection/ConnectionFactoryUtils.java index 97fc2997b1..1418433d33 100644 --- a/spring-jms/src/main/java/org/springframework/jms/connection/ConnectionFactoryUtils.java +++ b/spring-jms/src/main/java/org/springframework/jms/connection/ConnectionFactoryUtils.java @@ -30,6 +30,7 @@ import javax.jms.TopicSession; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.lang.Nullable; import org.springframework.transaction.support.ResourceHolderSynchronization; import org.springframework.transaction.support.TransactionSynchronizationManager; import org.springframework.util.Assert; @@ -64,7 +65,7 @@ public abstract class ConnectionFactoryUtils { * @see SmartConnectionFactory#shouldStop * @see org.springframework.jms.support.JmsUtils#closeConnection */ - public static void releaseConnection(Connection con, ConnectionFactory cf, boolean started) { + public static void releaseConnection(Connection con, @Nullable ConnectionFactory cf, boolean started) { if (con == null) { return; } @@ -131,8 +132,9 @@ public abstract class ConnectionFactoryUtils { * @return the transactional Session, or {@code null} if none found * @throws JMSException in case of JMS failure */ + @Nullable public static Session getTransactionalSession(final ConnectionFactory cf, - final Connection existingCon, final boolean synchedLocalTransactionAllowed) + @Nullable final Connection existingCon, final boolean synchedLocalTransactionAllowed) throws JMSException { return doGetTransactionalSession(cf, new ResourceFactory() { @@ -173,8 +175,9 @@ public abstract class ConnectionFactoryUtils { * @return the transactional Session, or {@code null} if none found * @throws JMSException in case of JMS failure */ + @Nullable public static QueueSession getTransactionalQueueSession(final QueueConnectionFactory cf, - final QueueConnection existingCon, final boolean synchedLocalTransactionAllowed) + @Nullable final QueueConnection existingCon, final boolean synchedLocalTransactionAllowed) throws JMSException { return (QueueSession) doGetTransactionalSession(cf, new ResourceFactory() { @@ -215,8 +218,9 @@ public abstract class ConnectionFactoryUtils { * @return the transactional Session, or {@code null} if none found * @throws JMSException in case of JMS failure */ + @Nullable public static TopicSession getTransactionalTopicSession(final TopicConnectionFactory cf, - final TopicConnection existingCon, final boolean synchedLocalTransactionAllowed) + @Nullable final TopicConnection existingCon, final boolean synchedLocalTransactionAllowed) throws JMSException { return (TopicSession) doGetTransactionalSession(cf, new ResourceFactory() { @@ -256,6 +260,7 @@ public abstract class ConnectionFactoryUtils { * @throws JMSException in case of JMS failure * @see #doGetTransactionalSession(javax.jms.ConnectionFactory, ResourceFactory, boolean) */ + @Nullable public static Session doGetTransactionalSession( ConnectionFactory connectionFactory, ResourceFactory resourceFactory) throws JMSException { @@ -274,6 +279,7 @@ public abstract class ConnectionFactoryUtils { * @return the transactional Session, or {@code null} if none found * @throws JMSException in case of JMS failure */ + @Nullable public static Session doGetTransactionalSession( ConnectionFactory connectionFactory, ResourceFactory resourceFactory, boolean startConnection) throws JMSException { @@ -361,6 +367,7 @@ public abstract class ConnectionFactoryUtils { * @return an appropriate Session fetched from the holder, * or {@code null} if none found */ + @Nullable Session getSession(JmsResourceHolder holder); /** @@ -369,6 +376,7 @@ public abstract class ConnectionFactoryUtils { * @return an appropriate Connection fetched from the holder, * or {@code null} if none found */ + @Nullable Connection getConnection(JmsResourceHolder holder); /** diff --git a/spring-jms/src/main/java/org/springframework/jms/connection/JmsResourceHolder.java b/spring-jms/src/main/java/org/springframework/jms/connection/JmsResourceHolder.java index b97a8a26da..e8119a8015 100644 --- a/spring-jms/src/main/java/org/springframework/jms/connection/JmsResourceHolder.java +++ b/spring-jms/src/main/java/org/springframework/jms/connection/JmsResourceHolder.java @@ -21,6 +21,7 @@ import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; + import javax.jms.Connection; import javax.jms.ConnectionFactory; import javax.jms.JMSException; @@ -30,6 +31,7 @@ import javax.jms.TransactionInProgressException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.lang.Nullable; import org.springframework.transaction.support.ResourceHolderSupport; import org.springframework.transaction.support.TransactionSynchronizationManager; import org.springframework.util.Assert; @@ -77,7 +79,7 @@ public class JmsResourceHolder extends ResourceHolderSupport { * @param connectionFactory the JMS ConnectionFactory that this * resource holder is associated with (may be {@code null}) */ - public JmsResourceHolder(ConnectionFactory connectionFactory) { + public JmsResourceHolder(@Nullable ConnectionFactory connectionFactory) { this.connectionFactory = connectionFactory; } @@ -108,7 +110,7 @@ public class JmsResourceHolder extends ResourceHolderSupport { * @param connection the JMS Connection * @param session the JMS Session */ - public JmsResourceHolder(ConnectionFactory connectionFactory, Connection connection, Session session) { + public JmsResourceHolder(@Nullable ConnectionFactory connectionFactory, Connection connection, Session session) { this.connectionFactory = connectionFactory; addConnection(connection); addSession(session, connection); diff --git a/spring-jms/src/main/java/org/springframework/jms/connection/SingleConnectionFactory.java b/spring-jms/src/main/java/org/springframework/jms/connection/SingleConnectionFactory.java index 7790c5d7b1..e58ed4c356 100644 --- a/spring-jms/src/main/java/org/springframework/jms/connection/SingleConnectionFactory.java +++ b/spring-jms/src/main/java/org/springframework/jms/connection/SingleConnectionFactory.java @@ -24,6 +24,7 @@ import java.util.ArrayList; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; + import javax.jms.Connection; import javax.jms.ConnectionFactory; import javax.jms.ExceptionListener; @@ -40,6 +41,7 @@ import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.InitializingBean; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -144,6 +146,7 @@ public class SingleConnectionFactory implements ConnectionFactory, QueueConnecti * Return the target ConnectionFactory which will be used to lazily * create a single Connection, if any. */ + @org.springframework.lang.Nullable public ConnectionFactory getTargetConnectionFactory() { return this.targetConnectionFactory; } @@ -165,6 +168,7 @@ public class SingleConnectionFactory implements ConnectionFactory, QueueConnecti * Return a JMS client ID for the single Connection created and exposed * by this ConnectionFactory, if any. */ + @org.springframework.lang.Nullable protected String getClientId() { return this.clientId; } @@ -182,6 +186,7 @@ public class SingleConnectionFactory implements ConnectionFactory, QueueConnecti * Return the JMS ExceptionListener implementation that should be registered * with the single Connection created by this factory, if any. */ + @Nullable protected ExceptionListener getExceptionListener() { return this.exceptionListener; } @@ -436,6 +441,7 @@ public class SingleConnectionFactory implements ConnectionFactory, QueueConnecti * creation of a raw standard Session * @throws JMSException if thrown by the JMS API */ + @Nullable protected Session getSession(Connection con, Integer mode) throws JMSException { return null; } diff --git a/spring-jms/src/main/java/org/springframework/jms/connection/package-info.java b/spring-jms/src/main/java/org/springframework/jms/connection/package-info.java index e6c2254c3a..24f972498a 100644 --- a/spring-jms/src/main/java/org/springframework/jms/connection/package-info.java +++ b/spring-jms/src/main/java/org/springframework/jms/connection/package-info.java @@ -2,4 +2,7 @@ * Provides a PlatformTransactionManager implementation for a single * JMS ConnectionFactory, and a SingleConnectionFactory adapter. */ +@NonNullApi package org.springframework.jms.connection; + +import org.springframework.lang.NonNullApi; diff --git a/spring-jms/src/main/java/org/springframework/jms/core/BrowserCallback.java b/spring-jms/src/main/java/org/springframework/jms/core/BrowserCallback.java index 3a544cb495..8b55d0010e 100644 --- a/spring-jms/src/main/java/org/springframework/jms/core/BrowserCallback.java +++ b/spring-jms/src/main/java/org/springframework/jms/core/BrowserCallback.java @@ -20,6 +20,8 @@ import javax.jms.JMSException; import javax.jms.QueueBrowser; import javax.jms.Session; +import org.springframework.lang.Nullable; + /** * Callback for browsing the messages in a JMS queue. * @@ -44,6 +46,7 @@ public interface BrowserCallback { * (or {@code null} if none) * @throws javax.jms.JMSException if thrown by JMS API methods */ + @Nullable T doInJms(Session session, QueueBrowser browser) throws JMSException; } diff --git a/spring-jms/src/main/java/org/springframework/jms/core/JmsMessageOperations.java b/spring-jms/src/main/java/org/springframework/jms/core/JmsMessageOperations.java index c861d4503f..0840b5a655 100644 --- a/spring-jms/src/main/java/org/springframework/jms/core/JmsMessageOperations.java +++ b/spring-jms/src/main/java/org/springframework/jms/core/JmsMessageOperations.java @@ -17,8 +17,10 @@ package org.springframework.jms.core; import java.util.Map; + import javax.jms.Destination; +import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessagingException; import org.springframework.messaging.core.MessagePostProcessor; @@ -100,6 +102,7 @@ public interface JmsMessageOperations extends MessageSendingOperations receive(String destinationName) throws MessagingException; /** @@ -110,6 +113,7 @@ public interface JmsMessageOperations extends MessageSendingOperations T receiveAndConvert(String destinationName, Class targetClass) throws MessagingException; /** @@ -119,6 +123,7 @@ public interface JmsMessageOperations extends MessageSendingOperations sendAndReceive(String destinationName, Message requestMessage) throws MessagingException; /** @@ -132,6 +137,7 @@ public interface JmsMessageOperations extends MessageSendingOperations T convertSendAndReceive(String destinationName, Object request, Class targetClass) throws MessagingException; /** @@ -146,6 +152,7 @@ public interface JmsMessageOperations extends MessageSendingOperations T convertSendAndReceive(String destinationName, Object request, Map headers, Class targetClass) throws MessagingException; @@ -162,6 +169,7 @@ public interface JmsMessageOperations extends MessageSendingOperations T convertSendAndReceive(String destinationName, Object request, Class targetClass, MessagePostProcessor requestPostProcessor) throws MessagingException; @@ -178,6 +186,7 @@ public interface JmsMessageOperations extends MessageSendingOperations T convertSendAndReceive(String destinationName, Object request, Map headers, Class targetClass, MessagePostProcessor requestPostProcessor) throws MessagingException; diff --git a/spring-jms/src/main/java/org/springframework/jms/core/JmsOperations.java b/spring-jms/src/main/java/org/springframework/jms/core/JmsOperations.java index ba66ef695f..895dc50af0 100644 --- a/spring-jms/src/main/java/org/springframework/jms/core/JmsOperations.java +++ b/spring-jms/src/main/java/org/springframework/jms/core/JmsOperations.java @@ -21,6 +21,7 @@ import javax.jms.Message; import javax.jms.Queue; import org.springframework.jms.JmsException; +import org.springframework.lang.Nullable; /** * Specifies a basic set of JMS operations. @@ -202,6 +203,7 @@ public interface JmsOperations { * @return the message received by the consumer, or {@code null} if the timeout expires * @throws JmsException checked JMSException converted to unchecked */ + @Nullable Message receive() throws JmsException; /** @@ -213,6 +215,7 @@ public interface JmsOperations { * @return the message received by the consumer, or {@code null} if the timeout expires * @throws JmsException checked JMSException converted to unchecked */ + @Nullable Message receive(Destination destination) throws JmsException; /** @@ -225,6 +228,7 @@ public interface JmsOperations { * @return the message received by the consumer, or {@code null} if the timeout expires * @throws JmsException checked JMSException converted to unchecked */ + @Nullable Message receive(String destinationName) throws JmsException; /** @@ -238,6 +242,7 @@ public interface JmsOperations { * @return the message received by the consumer, or {@code null} if the timeout expires * @throws JmsException checked JMSException converted to unchecked */ + @Nullable Message receiveSelected(String messageSelector) throws JmsException; /** @@ -251,6 +256,7 @@ public interface JmsOperations { * @return the message received by the consumer, or {@code null} if the timeout expires * @throws JmsException checked JMSException converted to unchecked */ + @Nullable Message receiveSelected(Destination destination, String messageSelector) throws JmsException; /** @@ -265,6 +271,7 @@ public interface JmsOperations { * @return the message received by the consumer, or {@code null} if the timeout expires * @throws JmsException checked JMSException converted to unchecked */ + @Nullable Message receiveSelected(String destinationName, String messageSelector) throws JmsException; @@ -282,6 +289,7 @@ public interface JmsOperations { * @return the message produced for the consumer or {@code null} if the timeout expires. * @throws JmsException checked JMSException converted to unchecked */ + @Nullable Object receiveAndConvert() throws JmsException; /** @@ -294,6 +302,7 @@ public interface JmsOperations { * @return the message produced for the consumer or {@code null} if the timeout expires. * @throws JmsException checked JMSException converted to unchecked */ + @Nullable Object receiveAndConvert(Destination destination) throws JmsException; /** @@ -307,6 +316,7 @@ public interface JmsOperations { * @return the message produced for the consumer or {@code null} if the timeout expires. * @throws JmsException checked JMSException converted to unchecked */ + @Nullable Object receiveAndConvert(String destinationName) throws JmsException; /** @@ -321,6 +331,7 @@ public interface JmsOperations { * @return the message produced for the consumer or {@code null} if the timeout expires. * @throws JmsException checked JMSException converted to unchecked */ + @Nullable Object receiveSelectedAndConvert(String messageSelector) throws JmsException; /** @@ -335,6 +346,7 @@ public interface JmsOperations { * @return the message produced for the consumer or {@code null} if the timeout expires. * @throws JmsException checked JMSException converted to unchecked */ + @Nullable Object receiveSelectedAndConvert(Destination destination, String messageSelector) throws JmsException; /** @@ -350,6 +362,7 @@ public interface JmsOperations { * @return the message produced for the consumer or {@code null} if the timeout expires. * @throws JmsException checked JMSException converted to unchecked */ + @Nullable Object receiveSelectedAndConvert(String destinationName, String messageSelector) throws JmsException; @@ -369,6 +382,7 @@ public interface JmsOperations { * @throws JmsException checked JMSException converted to unchecked * @since 4.1 */ + @Nullable Message sendAndReceive(MessageCreator messageCreator) throws JmsException; /** @@ -383,6 +397,7 @@ public interface JmsOperations { * @throws JmsException checked JMSException converted to unchecked * @since 4.1 */ + @Nullable Message sendAndReceive(Destination destination, MessageCreator messageCreator) throws JmsException; /** @@ -398,6 +413,7 @@ public interface JmsOperations { * @throws JmsException checked JMSException converted to unchecked * @since 4.1 */ + @Nullable Message sendAndReceive(String destinationName, MessageCreator messageCreator) throws JmsException; diff --git a/spring-jms/src/main/java/org/springframework/jms/core/JmsTemplate.java b/spring-jms/src/main/java/org/springframework/jms/core/JmsTemplate.java index 825879f295..bfe43e242c 100644 --- a/spring-jms/src/main/java/org/springframework/jms/core/JmsTemplate.java +++ b/spring-jms/src/main/java/org/springframework/jms/core/JmsTemplate.java @@ -17,6 +17,7 @@ package org.springframework.jms.core; import java.lang.reflect.Method; + import javax.jms.Connection; import javax.jms.ConnectionFactory; import javax.jms.DeliveryMode; @@ -38,6 +39,7 @@ import org.springframework.jms.support.QosSettings; import org.springframework.jms.support.converter.MessageConverter; import org.springframework.jms.support.converter.SimpleMessageConverter; import org.springframework.jms.support.destination.JmsDestinationAccessor; +import org.springframework.lang.Nullable; import org.springframework.transaction.support.TransactionSynchronizationManager; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; @@ -786,7 +788,8 @@ public class JmsTemplate extends JmsDestinationAccessor implements JmsOperations * @return the JMS Message received, or {@code null} if none * @throws JMSException if thrown by JMS API methods */ - protected Message doReceive(Session session, Destination destination, String messageSelector) + @Nullable + protected Message doReceive(Session session, Destination destination, @Nullable String messageSelector) throws JMSException { return doReceive(session, createConsumer(session, destination, messageSelector)); @@ -799,6 +802,7 @@ public class JmsTemplate extends JmsDestinationAccessor implements JmsOperations * @return the JMS Message received, or {@code null} if none * @throws JMSException if thrown by JMS API methods */ + @Nullable protected Message doReceive(Session session, MessageConsumer consumer) throws JMSException { try { // Use transaction timeout (if available). @@ -869,7 +873,8 @@ public class JmsTemplate extends JmsDestinationAccessor implements JmsOperations * @param message the JMS Message to convert (can be {@code null}) * @return the content of the message, or {@code null} if none */ - protected Object doConvertFromMessage(Message message) { + @Nullable + protected Object doConvertFromMessage(@Nullable Message message) { if (message != null) { try { return getRequiredMessageConverter().fromMessage(message); @@ -924,6 +929,7 @@ public class JmsTemplate extends JmsDestinationAccessor implements JmsOperations *

    Return the response message or {@code null} if no message has * @throws JMSException if thrown by JMS API methods */ + @Nullable protected Message doSendAndReceive(Session session, Destination destination, MessageCreator messageCreator) throws JMSException { @@ -1065,6 +1071,7 @@ public class JmsTemplate extends JmsDestinationAccessor implements JmsOperations * @return an appropriate Connection fetched from the holder, * or {@code null} if none found */ + @Nullable protected Connection getConnection(JmsResourceHolder holder) { return holder.getConnection(); } @@ -1076,6 +1083,7 @@ public class JmsTemplate extends JmsDestinationAccessor implements JmsOperations * @return an appropriate Session fetched from the holder, * or {@code null} if none found */ + @Nullable protected Session getSession(JmsResourceHolder holder) { return holder.getSession(); } @@ -1141,7 +1149,7 @@ public class JmsTemplate extends JmsDestinationAccessor implements JmsOperations * @return the new JMS MessageConsumer * @throws JMSException if thrown by JMS API methods */ - protected MessageConsumer createConsumer(Session session, Destination destination, String messageSelector) + protected MessageConsumer createConsumer(Session session, Destination destination, @Nullable String messageSelector) throws JMSException { // Only pass in the NoLocal flag in case of a Topic: @@ -1168,7 +1176,7 @@ public class JmsTemplate extends JmsDestinationAccessor implements JmsOperations * @see #setMessageIdEnabled * @see #setMessageTimestampEnabled */ - protected QueueBrowser createBrowser(Session session, Queue queue, String messageSelector) + protected QueueBrowser createBrowser(Session session, Queue queue, @Nullable String messageSelector) throws JMSException { return session.createBrowser(queue, messageSelector); diff --git a/spring-jms/src/main/java/org/springframework/jms/core/ProducerCallback.java b/spring-jms/src/main/java/org/springframework/jms/core/ProducerCallback.java index e1edfbf5b4..d81480565a 100644 --- a/spring-jms/src/main/java/org/springframework/jms/core/ProducerCallback.java +++ b/spring-jms/src/main/java/org/springframework/jms/core/ProducerCallback.java @@ -20,6 +20,8 @@ import javax.jms.JMSException; import javax.jms.MessageProducer; import javax.jms.Session; +import org.springframework.lang.Nullable; + /** * Callback for sending a message to a JMS destination. * @@ -49,6 +51,7 @@ public interface ProducerCallback { * (or {@code null} if none) * @throws javax.jms.JMSException if thrown by JMS API methods */ + @Nullable T doInJms(Session session, MessageProducer producer) throws JMSException; } diff --git a/spring-jms/src/main/java/org/springframework/jms/core/SessionCallback.java b/spring-jms/src/main/java/org/springframework/jms/core/SessionCallback.java index 1a7a171b1b..5b8b76e077 100644 --- a/spring-jms/src/main/java/org/springframework/jms/core/SessionCallback.java +++ b/spring-jms/src/main/java/org/springframework/jms/core/SessionCallback.java @@ -19,6 +19,8 @@ package org.springframework.jms.core; import javax.jms.JMSException; import javax.jms.Session; +import org.springframework.lang.Nullable; + /** * Callback for executing any number of operations on a provided {@link Session}. * @@ -40,6 +42,7 @@ public interface SessionCallback { * (or {@code null} if none) * @throws javax.jms.JMSException if thrown by JMS API methods */ + @Nullable T doInJms(Session session) throws JMSException; } diff --git a/spring-jms/src/main/java/org/springframework/jms/core/package-info.java b/spring-jms/src/main/java/org/springframework/jms/core/package-info.java index 6be99ccf7e..48276a94b5 100644 --- a/spring-jms/src/main/java/org/springframework/jms/core/package-info.java +++ b/spring-jms/src/main/java/org/springframework/jms/core/package-info.java @@ -2,4 +2,7 @@ * Core package of the JMS support. * Provides a JmsTemplate class and various callback interfaces. */ +@NonNullApi package org.springframework.jms.core; + +import org.springframework.lang.NonNullApi; diff --git a/spring-jms/src/main/java/org/springframework/jms/core/support/package-info.java b/spring-jms/src/main/java/org/springframework/jms/core/support/package-info.java index 19ae921bea..443ae9fa9c 100644 --- a/spring-jms/src/main/java/org/springframework/jms/core/support/package-info.java +++ b/spring-jms/src/main/java/org/springframework/jms/core/support/package-info.java @@ -2,4 +2,7 @@ * Classes supporting the {@code org.springframework.jms.core} package. * Contains a base class for JmsTemplate usage. */ +@NonNullApi package org.springframework.jms.core.support; + +import org.springframework.lang.NonNullApi; diff --git a/spring-jms/src/main/java/org/springframework/jms/listener/AbstractJmsListeningContainer.java b/spring-jms/src/main/java/org/springframework/jms/listener/AbstractJmsListeningContainer.java index 6083cdaa34..14eae39fbc 100644 --- a/spring-jms/src/main/java/org/springframework/jms/listener/AbstractJmsListeningContainer.java +++ b/spring-jms/src/main/java/org/springframework/jms/listener/AbstractJmsListeningContainer.java @@ -29,6 +29,7 @@ import org.springframework.jms.JmsException; import org.springframework.jms.connection.ConnectionFactoryUtils; import org.springframework.jms.support.JmsUtils; import org.springframework.jms.support.destination.JmsDestinationAccessor; +import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; /** @@ -100,6 +101,7 @@ public abstract class AbstractJmsListeningContainer extends JmsDestinationAccess * Return the JMS client ID for the shared Connection created and used * by this container, if any. */ + @Nullable public String getClientId() { return this.clientId; } @@ -146,6 +148,7 @@ public abstract class AbstractJmsListeningContainer extends JmsDestinationAccess * Return the bean name that this listener container has been assigned * in its containing bean factory, if any. */ + @Nullable protected final String getBeanName() { return this.beanName; } diff --git a/spring-jms/src/main/java/org/springframework/jms/listener/AbstractMessageListenerContainer.java b/spring-jms/src/main/java/org/springframework/jms/listener/AbstractMessageListenerContainer.java index 49e4c8766f..6c6a5af188 100644 --- a/spring-jms/src/main/java/org/springframework/jms/listener/AbstractMessageListenerContainer.java +++ b/spring-jms/src/main/java/org/springframework/jms/listener/AbstractMessageListenerContainer.java @@ -18,6 +18,7 @@ package org.springframework.jms.listener; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; + import javax.jms.Connection; import javax.jms.Destination; import javax.jms.ExceptionListener; @@ -32,6 +33,7 @@ import javax.jms.Topic; import org.springframework.jms.support.JmsUtils; import org.springframework.jms.support.QosSettings; import org.springframework.jms.support.converter.MessageConverter; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.ErrorHandler; @@ -213,6 +215,7 @@ public abstract class AbstractMessageListenerContainer extends AbstractJmsListen * if the configured destination is not an actual {@link Destination} type; * c.f. {@link #setDestinationName(String) when the destination is a String}. */ + @Nullable public Destination getDestination() { return (this.destination instanceof Destination ? (Destination) this.destination : null); } @@ -229,7 +232,7 @@ public abstract class AbstractMessageListenerContainer extends AbstractJmsListen * @param destinationName the desired destination (can be {@code null}) * @see #setDestination(javax.jms.Destination) */ - public void setDestinationName(String destinationName) { + public void setDestinationName(@Nullable String destinationName) { Assert.notNull(destinationName, "'destinationName' must not be null"); this.destination = destinationName; } @@ -240,6 +243,7 @@ public abstract class AbstractMessageListenerContainer extends AbstractJmsListen * {@link String} type; c.f. {@link #setDestination(Destination) when * it is an actual Destination}. */ + @Nullable public String getDestinationName() { return (this.destination instanceof String ? (String) this.destination : null); } @@ -261,13 +265,14 @@ public abstract class AbstractMessageListenerContainer extends AbstractJmsListen * DefaultMessageListenerContainer, as long as the cache level is less than * CACHE_CONSUMER). However, this is considered advanced usage; use it with care! */ - public void setMessageSelector(String messageSelector) { + public void setMessageSelector(@Nullable String messageSelector) { this.messageSelector = messageSelector; } /** * Return the JMS message selector expression (or {@code null} if none). */ + @Nullable public String getMessageSelector() { return this.messageSelector; } @@ -415,6 +420,7 @@ public abstract class AbstractMessageListenerContainer extends AbstractJmsListen * Return the name of a subscription to create, if any. * @since 4.1 */ + @Nullable public String getSubscriptionName() { return this.subscriptionName; } @@ -441,6 +447,7 @@ public abstract class AbstractMessageListenerContainer extends AbstractJmsListen /** * Return the name of a durable subscription to create, if any. */ + @Nullable public String getDurableSubscriptionName() { return (this.subscriptionDurable ? this.subscriptionName : null); } @@ -500,7 +507,7 @@ public abstract class AbstractMessageListenerContainer extends AbstractJmsListen * to use the default vas. * @since 5.0 */ - public void setReplyQosSettings(QosSettings replyQosSettings) { + public void setReplyQosSettings(@Nullable QosSettings replyQosSettings) { this.replyQosSettings = replyQosSettings; } @@ -534,6 +541,7 @@ public abstract class AbstractMessageListenerContainer extends AbstractJmsListen * Return the JMS ExceptionListener to notify in case of a JMSException thrown * by the registered message listener or the invocation infrastructure, if any. */ + @Nullable public ExceptionListener getExceptionListener() { return this.exceptionListener; } @@ -553,6 +561,7 @@ public abstract class AbstractMessageListenerContainer extends AbstractJmsListen * while processing a Message. * @since 4.1 */ + @Nullable public ErrorHandler getErrorHandler() { return this.errorHandler; } @@ -864,6 +873,7 @@ public abstract class AbstractMessageListenerContainer extends AbstractJmsListen * @return the new JMS MessageConsumer * @throws javax.jms.JMSException if thrown by JMS API methods */ + @Nullable protected MessageConsumer createConsumer(Session session, Destination destination) throws JMSException { if (isPubSubDomain() && destination instanceof Topic) { if (isSubscriptionShared()) { diff --git a/spring-jms/src/main/java/org/springframework/jms/listener/AbstractPollingMessageListenerContainer.java b/spring-jms/src/main/java/org/springframework/jms/listener/AbstractPollingMessageListenerContainer.java index 910125f80a..7205e6481a 100644 --- a/spring-jms/src/main/java/org/springframework/jms/listener/AbstractPollingMessageListenerContainer.java +++ b/spring-jms/src/main/java/org/springframework/jms/listener/AbstractPollingMessageListenerContainer.java @@ -27,6 +27,7 @@ import org.springframework.jms.connection.ConnectionFactoryUtils; import org.springframework.jms.connection.JmsResourceHolder; import org.springframework.jms.connection.SingleConnectionFactory; import org.springframework.jms.support.JmsUtils; +import org.springframework.lang.Nullable; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.TransactionStatus; import org.springframework.transaction.support.DefaultTransactionDefinition; @@ -267,7 +268,7 @@ public abstract class AbstractPollingMessageListenerContainer extends AbstractMe * @see #doExecuteListener(javax.jms.Session, javax.jms.Message) */ protected boolean doReceiveAndExecute( - Object invoker, Session session, MessageConsumer consumer, TransactionStatus status) + Object invoker, Session session, MessageConsumer consumer, @Nullable TransactionStatus status) throws JMSException { Connection conToClose = null; @@ -443,6 +444,7 @@ public abstract class AbstractPollingMessageListenerContainer extends AbstractMe * @return an appropriate Connection fetched from the holder, * or {@code null} if none found */ + @Nullable protected Connection getConnection(JmsResourceHolder holder) { return holder.getConnection(); } @@ -454,6 +456,7 @@ public abstract class AbstractPollingMessageListenerContainer extends AbstractMe * @return an appropriate Session fetched from the holder, * or {@code null} if none found */ + @Nullable protected Session getSession(JmsResourceHolder holder) { return holder.getSession(); } diff --git a/spring-jms/src/main/java/org/springframework/jms/listener/MessageListenerContainer.java b/spring-jms/src/main/java/org/springframework/jms/listener/MessageListenerContainer.java index ac21ec9de7..cf8efd4115 100644 --- a/spring-jms/src/main/java/org/springframework/jms/listener/MessageListenerContainer.java +++ b/spring-jms/src/main/java/org/springframework/jms/listener/MessageListenerContainer.java @@ -20,6 +20,7 @@ import org.springframework.context.SmartLifecycle; import org.springframework.jms.support.QosSettings; import org.springframework.jms.support.converter.MessageConverter; import org.springframework.jms.support.destination.DestinationResolver; +import org.springframework.lang.Nullable; /** * Internal abstraction used by the framework representing a message @@ -41,12 +42,14 @@ public interface MessageListenerContainer extends SmartLifecycle { * Return the {@link MessageConverter} that can be used to * convert {@link javax.jms.Message}, if any. */ + @Nullable MessageConverter getMessageConverter(); /** * Return the {@link DestinationResolver} to use to resolve * destinations by names. */ + @Nullable DestinationResolver getDestinationResolver(); /** @@ -68,6 +71,7 @@ public interface MessageListenerContainer extends SmartLifecycle { * if the broker's defaults should be used. * @since 5.0 */ + @Nullable QosSettings getReplyQosSettings(); } diff --git a/spring-jms/src/main/java/org/springframework/jms/listener/adapter/AbstractAdaptableMessageListener.java b/spring-jms/src/main/java/org/springframework/jms/listener/adapter/AbstractAdaptableMessageListener.java index d68de9bdaa..ede0ea17a3 100644 --- a/spring-jms/src/main/java/org/springframework/jms/listener/adapter/AbstractAdaptableMessageListener.java +++ b/spring-jms/src/main/java/org/springframework/jms/listener/adapter/AbstractAdaptableMessageListener.java @@ -40,6 +40,7 @@ import org.springframework.jms.support.converter.SimpleMessageConverter; import org.springframework.jms.support.converter.SmartMessageConverter; import org.springframework.jms.support.destination.DestinationResolver; import org.springframework.jms.support.destination.DynamicDestinationResolver; +import org.springframework.lang.Nullable; import org.springframework.messaging.MessageHeaders; import org.springframework.util.Assert; @@ -176,7 +177,7 @@ public abstract class AbstractAdaptableMessageListener * {@code null} to use the default values. * @since 5.0 */ - public void setResponseQosSettings(QosSettings responseQosSettings) { + public void setResponseQosSettings(@Nullable QosSettings responseQosSettings) { this.responseQosSettings = responseQosSettings; } @@ -184,6 +185,7 @@ public abstract class AbstractAdaptableMessageListener * Return the {@link QosSettings} to use when sending a response or {@code null} if * the defaults should be used. */ + @Nullable protected QosSettings getResponseQosSettings() { return this.responseQosSettings; } @@ -256,7 +258,7 @@ public abstract class AbstractAdaptableMessageListener * @see #getResponseDestination * @see #sendResponse */ - protected void handleResult(Object result, Message request, Session session) { + protected void handleResult(Object result, Message request, @Nullable Session session) { if (session != null) { if (logger.isDebugEnabled()) { logger.debug("Listener method returned result [" + result + @@ -394,6 +396,7 @@ public abstract class AbstractAdaptableMessageListener * @see #setDefaultResponseTopicName * @see #setDestinationResolver */ + @Nullable protected Destination resolveDefaultResponseDestination(Session session) throws JMSException { if (this.defaultResponseDestination instanceof Destination) { return (Destination) this.defaultResponseDestination; diff --git a/spring-jms/src/main/java/org/springframework/jms/listener/adapter/JmsResponse.java b/spring-jms/src/main/java/org/springframework/jms/listener/adapter/JmsResponse.java index 02f45670ed..b5df11e9d9 100644 --- a/spring-jms/src/main/java/org/springframework/jms/listener/adapter/JmsResponse.java +++ b/spring-jms/src/main/java/org/springframework/jms/listener/adapter/JmsResponse.java @@ -21,6 +21,7 @@ import javax.jms.JMSException; import javax.jms.Session; import org.springframework.jms.support.destination.DestinationResolver; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -86,6 +87,7 @@ public class JmsResponse { * @return the {@link Destination} to use * @throws JMSException if the DestinationResolver failed to resolve the destination */ + @Nullable public Destination resolveDestination(DestinationResolver destinationResolver, Session session) throws JMSException { diff --git a/spring-jms/src/main/java/org/springframework/jms/listener/adapter/package-info.java b/spring-jms/src/main/java/org/springframework/jms/listener/adapter/package-info.java index be184c5204..0d5bfba59f 100644 --- a/spring-jms/src/main/java/org/springframework/jms/listener/adapter/package-info.java +++ b/spring-jms/src/main/java/org/springframework/jms/listener/adapter/package-info.java @@ -3,4 +3,7 @@ * methods, converting messages to appropriate message content types * (such as String or byte array) that get passed into listener methods. */ +@NonNullApi package org.springframework.jms.listener.adapter; + +import org.springframework.lang.NonNullApi; diff --git a/spring-jms/src/main/java/org/springframework/jms/listener/endpoint/JmsActivationSpecConfig.java b/spring-jms/src/main/java/org/springframework/jms/listener/endpoint/JmsActivationSpecConfig.java index f2a647d07c..3bbb78806d 100644 --- a/spring-jms/src/main/java/org/springframework/jms/listener/endpoint/JmsActivationSpecConfig.java +++ b/spring-jms/src/main/java/org/springframework/jms/listener/endpoint/JmsActivationSpecConfig.java @@ -21,6 +21,7 @@ import javax.jms.Session; import org.springframework.core.Constants; import org.springframework.jms.support.QosSettings; import org.springframework.jms.support.converter.MessageConverter; +import org.springframework.lang.Nullable; /** * Common configuration object for activating a JMS message endpoint. @@ -267,6 +268,7 @@ public class JmsActivationSpecConfig { /** * Return the {@link MessageConverter} to use, if any. */ + @Nullable public MessageConverter getMessageConverter() { return this.messageConverter; } diff --git a/spring-jms/src/main/java/org/springframework/jms/listener/endpoint/JmsMessageEndpointManager.java b/spring-jms/src/main/java/org/springframework/jms/listener/endpoint/JmsMessageEndpointManager.java index 509d4e3170..f1c7e12ddb 100644 --- a/spring-jms/src/main/java/org/springframework/jms/listener/endpoint/JmsMessageEndpointManager.java +++ b/spring-jms/src/main/java/org/springframework/jms/listener/endpoint/JmsMessageEndpointManager.java @@ -25,6 +25,7 @@ import org.springframework.jms.listener.MessageListenerContainer; import org.springframework.jms.support.QosSettings; import org.springframework.jms.support.converter.MessageConverter; import org.springframework.jms.support.destination.DestinationResolver; +import org.springframework.lang.Nullable; /** * Extension of the generic JCA 1.5 @@ -144,6 +145,7 @@ public class JmsMessageEndpointManager extends GenericMessageEndpointManager * Return the {@link JmsActivationSpecConfig} object that this endpoint manager * should use for activating its listener. Return {@code null} if none is set. */ + @Nullable public JmsActivationSpecConfig getActivationSpecConfig() { return this.activationSpecConfig; } diff --git a/spring-jms/src/main/java/org/springframework/jms/listener/endpoint/StandardJmsActivationSpecFactory.java b/spring-jms/src/main/java/org/springframework/jms/listener/endpoint/StandardJmsActivationSpecFactory.java index 4cc2bd97d7..ba4e4fb2ec 100644 --- a/spring-jms/src/main/java/org/springframework/jms/listener/endpoint/StandardJmsActivationSpecFactory.java +++ b/spring-jms/src/main/java/org/springframework/jms/listener/endpoint/StandardJmsActivationSpecFactory.java @@ -17,6 +17,7 @@ package org.springframework.jms.listener.endpoint; import java.util.Map; + import javax.jms.JMSException; import javax.jms.Queue; import javax.jms.Session; @@ -29,6 +30,7 @@ import org.springframework.beans.BeanWrapper; import org.springframework.beans.PropertyAccessorFactory; import org.springframework.jms.support.destination.DestinationResolutionException; import org.springframework.jms.support.destination.DestinationResolver; +import org.springframework.lang.Nullable; /** * Standard implementation of the {@link JmsActivationSpecFactory} interface. @@ -124,6 +126,7 @@ public class StandardJmsActivationSpecFactory implements JmsActivationSpecFactor * if not determinable * @see #setActivationSpecClass */ + @Nullable protected Class determineActivationSpecClass(ResourceAdapter adapter) { return null; } diff --git a/spring-jms/src/main/java/org/springframework/jms/listener/endpoint/package-info.java b/spring-jms/src/main/java/org/springframework/jms/listener/endpoint/package-info.java index a46729830a..c0723c40e4 100644 --- a/spring-jms/src/main/java/org/springframework/jms/listener/endpoint/package-info.java +++ b/spring-jms/src/main/java/org/springframework/jms/listener/endpoint/package-info.java @@ -1,4 +1,7 @@ /** * This package provides JCA-based endpoint management for JMS message listeners. */ +@NonNullApi package org.springframework.jms.listener.endpoint; + +import org.springframework.lang.NonNullApi; diff --git a/spring-jms/src/main/java/org/springframework/jms/listener/package-info.java b/spring-jms/src/main/java/org/springframework/jms/listener/package-info.java index e5086fce4e..99bf952e68 100644 --- a/spring-jms/src/main/java/org/springframework/jms/listener/package-info.java +++ b/spring-jms/src/main/java/org/springframework/jms/listener/package-info.java @@ -3,4 +3,7 @@ * It also offers the DefaultMessageListenerContainer and SimpleMessageListenerContainer * implementations, based on the plain JMS client API. */ +@NonNullApi package org.springframework.jms.listener; + +import org.springframework.lang.NonNullApi; diff --git a/spring-jms/src/main/java/org/springframework/jms/package-info.java b/spring-jms/src/main/java/org/springframework/jms/package-info.java index d6e972d7d2..2d3d230d26 100644 --- a/spring-jms/src/main/java/org/springframework/jms/package-info.java +++ b/spring-jms/src/main/java/org/springframework/jms/package-info.java @@ -2,4 +2,7 @@ * This package contains integration classes for JMS, * allowing for Spring-style JMS access. */ +@NonNullApi package org.springframework.jms; + +import org.springframework.lang.NonNullApi; diff --git a/spring-jms/src/main/java/org/springframework/jms/remoting/JmsInvokerServiceExporter.java b/spring-jms/src/main/java/org/springframework/jms/remoting/JmsInvokerServiceExporter.java index 8d5ba01cea..a2d8ca298c 100644 --- a/spring-jms/src/main/java/org/springframework/jms/remoting/JmsInvokerServiceExporter.java +++ b/spring-jms/src/main/java/org/springframework/jms/remoting/JmsInvokerServiceExporter.java @@ -27,6 +27,7 @@ import org.springframework.jms.listener.SessionAwareMessageListener; import org.springframework.jms.support.JmsUtils; import org.springframework.jms.support.converter.MessageConverter; import org.springframework.jms.support.converter.SimpleMessageConverter; +import org.springframework.lang.Nullable; import org.springframework.remoting.support.RemoteInvocation; import org.springframework.remoting.support.RemoteInvocationBasedExporter; import org.springframework.remoting.support.RemoteInvocationResult; @@ -111,6 +112,7 @@ public class JmsInvokerServiceExporter extends RemoteInvocationBasedExporter * in case of an invalid message that will simply be ignored) * @throws javax.jms.JMSException in case of message access failure */ + @Nullable protected RemoteInvocation readRemoteInvocation(Message requestMessage) throws JMSException { Object content = this.messageConverter.fromMessage(requestMessage); if (content instanceof RemoteInvocation) { @@ -178,6 +180,7 @@ public class JmsInvokerServiceExporter extends RemoteInvocationBasedExporter * @see #readRemoteInvocation * @see #setIgnoreInvalidRequests */ + @Nullable protected RemoteInvocation onInvalidRequest(Message requestMessage) throws JMSException { if (this.ignoreInvalidRequests) { if (logger.isWarnEnabled()) { diff --git a/spring-jms/src/main/java/org/springframework/jms/remoting/package-info.java b/spring-jms/src/main/java/org/springframework/jms/remoting/package-info.java index c203a9b061..1cb05b0e9f 100644 --- a/spring-jms/src/main/java/org/springframework/jms/remoting/package-info.java +++ b/spring-jms/src/main/java/org/springframework/jms/remoting/package-info.java @@ -5,4 +5,7 @@ * receivers, and provides a level of indirection between the client and the * service: They only need to agree on a queue name and a service interface. */ +@NonNullApi package org.springframework.jms.remoting; + +import org.springframework.lang.NonNullApi; diff --git a/spring-jms/src/main/java/org/springframework/jms/support/JmsUtils.java b/spring-jms/src/main/java/org/springframework/jms/support/JmsUtils.java index 7f9212a80b..15c761fad3 100644 --- a/spring-jms/src/main/java/org/springframework/jms/support/JmsUtils.java +++ b/spring-jms/src/main/java/org/springframework/jms/support/JmsUtils.java @@ -40,6 +40,7 @@ import org.springframework.jms.ResourceAllocationException; import org.springframework.jms.TransactionInProgressException; import org.springframework.jms.TransactionRolledBackException; import org.springframework.jms.UncategorizedJmsException; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -59,7 +60,7 @@ public abstract class JmsUtils { * This is useful for typical {@code finally} blocks in manual JMS code. * @param con the JMS Connection to close (may be {@code null}) */ - public static void closeConnection(Connection con) { + public static void closeConnection(@Nullable Connection con) { closeConnection(con, false); } @@ -69,7 +70,7 @@ public abstract class JmsUtils { * @param con the JMS Connection to close (may be {@code null}) * @param stop whether to call {@code stop()} before closing */ - public static void closeConnection(Connection con, boolean stop) { + public static void closeConnection(@Nullable Connection con, boolean stop) { if (con != null) { try { if (stop) { @@ -102,7 +103,7 @@ public abstract class JmsUtils { * This is useful for typical {@code finally} blocks in manual JMS code. * @param session the JMS Session to close (may be {@code null}) */ - public static void closeSession(Session session) { + public static void closeSession(@Nullable Session session) { if (session != null) { try { session.close(); @@ -122,7 +123,7 @@ public abstract class JmsUtils { * This is useful for typical {@code finally} blocks in manual JMS code. * @param producer the JMS MessageProducer to close (may be {@code null}) */ - public static void closeMessageProducer(MessageProducer producer) { + public static void closeMessageProducer(@Nullable MessageProducer producer) { if (producer != null) { try { producer.close(); @@ -142,7 +143,7 @@ public abstract class JmsUtils { * This is useful for typical {@code finally} blocks in manual JMS code. * @param consumer the JMS MessageConsumer to close (may be {@code null}) */ - public static void closeMessageConsumer(MessageConsumer consumer) { + public static void closeMessageConsumer(@Nullable MessageConsumer consumer) { if (consumer != null) { // Clear interruptions to ensure that the consumer closes successfully... // (working around misbehaving JMS providers such as ActiveMQ) @@ -171,7 +172,7 @@ public abstract class JmsUtils { * This is useful for typical {@code finally} blocks in manual JMS code. * @param browser the JMS QueueBrowser to close (may be {@code null}) */ - public static void closeQueueBrowser(QueueBrowser browser) { + public static void closeQueueBrowser(@Nullable QueueBrowser browser) { if (browser != null) { try { browser.close(); @@ -191,7 +192,7 @@ public abstract class JmsUtils { * This is useful for typical {@code finally} blocks in manual JMS code. * @param requestor the JMS QueueRequestor to close (may be {@code null}) */ - public static void closeQueueRequestor(QueueRequestor requestor) { + public static void closeQueueRequestor(@Nullable QueueRequestor requestor) { if (requestor != null) { try { requestor.close(); diff --git a/spring-jms/src/main/java/org/springframework/jms/support/converter/MappingJackson2MessageConverter.java b/spring-jms/src/main/java/org/springframework/jms/support/converter/MappingJackson2MessageConverter.java index 3285b655ad..41ffe651e9 100644 --- a/spring-jms/src/main/java/org/springframework/jms/support/converter/MappingJackson2MessageConverter.java +++ b/spring-jms/src/main/java/org/springframework/jms/support/converter/MappingJackson2MessageConverter.java @@ -23,6 +23,7 @@ import java.io.StringWriter; import java.io.UnsupportedEncodingException; import java.util.HashMap; import java.util.Map; + import javax.jms.BytesMessage; import javax.jms.JMSException; import javax.jms.Message; @@ -38,6 +39,7 @@ import com.fasterxml.jackson.databind.ObjectWriter; import org.springframework.beans.factory.BeanClassLoaderAware; import org.springframework.core.MethodParameter; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; @@ -456,6 +458,7 @@ public class MappingJackson2MessageConverter implements SmartMessageConverter, B * converter for the current conversion attempt * @return the serialization view class, or {@code null} if none */ + @Nullable protected Class getSerializationView(Object conversionHint) { if (conversionHint instanceof MethodParameter) { MethodParameter methodParam = (MethodParameter) conversionHint; diff --git a/spring-jms/src/main/java/org/springframework/jms/support/converter/MessageConversionException.java b/spring-jms/src/main/java/org/springframework/jms/support/converter/MessageConversionException.java index c4fa618353..f152d4fb05 100644 --- a/spring-jms/src/main/java/org/springframework/jms/support/converter/MessageConversionException.java +++ b/spring-jms/src/main/java/org/springframework/jms/support/converter/MessageConversionException.java @@ -17,6 +17,7 @@ package org.springframework.jms.support.converter; import org.springframework.jms.JmsException; +import org.springframework.lang.Nullable; /** * Thrown by {@link MessageConverter} implementations when the conversion @@ -42,7 +43,7 @@ public class MessageConversionException extends JmsException { * @param msg the detail message * @param cause the root cause (if any) */ - public MessageConversionException(String msg, Throwable cause) { + public MessageConversionException(String msg, @Nullable Throwable cause) { super(msg, cause); } diff --git a/spring-jms/src/main/java/org/springframework/jms/support/converter/MessageConverter.java b/spring-jms/src/main/java/org/springframework/jms/support/converter/MessageConverter.java index b466100830..a4282d35a7 100644 --- a/spring-jms/src/main/java/org/springframework/jms/support/converter/MessageConverter.java +++ b/spring-jms/src/main/java/org/springframework/jms/support/converter/MessageConverter.java @@ -20,6 +20,8 @@ import javax.jms.JMSException; import javax.jms.Message; import javax.jms.Session; +import org.springframework.lang.Nullable; + /** * Strategy interface that specifies a converter between Java objects and JMS messages. * @@ -54,6 +56,7 @@ public interface MessageConverter { * @throws javax.jms.JMSException if thrown by JMS API methods * @throws MessageConversionException in case of conversion failure */ + @Nullable Object fromMessage(Message message) throws JMSException, MessageConversionException; } diff --git a/spring-jms/src/main/java/org/springframework/jms/support/converter/SmartMessageConverter.java b/spring-jms/src/main/java/org/springframework/jms/support/converter/SmartMessageConverter.java index 2fb5cd734e..2b51febceb 100644 --- a/spring-jms/src/main/java/org/springframework/jms/support/converter/SmartMessageConverter.java +++ b/spring-jms/src/main/java/org/springframework/jms/support/converter/SmartMessageConverter.java @@ -20,6 +20,8 @@ import javax.jms.JMSException; import javax.jms.Message; import javax.jms.Session; +import org.springframework.lang.Nullable; + /** * An extended {@link MessageConverter} SPI with conversion hint support. * @@ -45,7 +47,7 @@ public interface SmartMessageConverter extends MessageConverter { * @throws MessageConversionException in case of conversion failure * @see #toMessage(Object, Session) */ - Message toMessage(Object object, Session session, Object conversionHint) + Message toMessage(Object object, Session session, @Nullable Object conversionHint) throws JMSException, MessageConversionException; } diff --git a/spring-jms/src/main/java/org/springframework/jms/support/converter/package-info.java b/spring-jms/src/main/java/org/springframework/jms/support/converter/package-info.java index 419a774b10..bef53603d3 100644 --- a/spring-jms/src/main/java/org/springframework/jms/support/converter/package-info.java +++ b/spring-jms/src/main/java/org/springframework/jms/support/converter/package-info.java @@ -2,4 +2,7 @@ * Provides a MessageConverter abstraction to convert * between Java objects and JMS messages. */ +@NonNullApi package org.springframework.jms.support.converter; + +import org.springframework.lang.NonNullApi; diff --git a/spring-jms/src/main/java/org/springframework/jms/support/destination/DestinationResolutionException.java b/spring-jms/src/main/java/org/springframework/jms/support/destination/DestinationResolutionException.java index e5be7c7297..72dcd54675 100644 --- a/spring-jms/src/main/java/org/springframework/jms/support/destination/DestinationResolutionException.java +++ b/spring-jms/src/main/java/org/springframework/jms/support/destination/DestinationResolutionException.java @@ -17,6 +17,7 @@ package org.springframework.jms.support.destination; import org.springframework.jms.JmsException; +import org.springframework.lang.Nullable; /** * Thrown by a DestinationResolver when it cannot resolve a destination name. @@ -41,7 +42,7 @@ public class DestinationResolutionException extends JmsException { * @param msg the detail message * @param cause the root cause (if any) */ - public DestinationResolutionException(String msg, Throwable cause) { + public DestinationResolutionException(String msg, @Nullable Throwable cause) { super(msg, cause); } diff --git a/spring-jms/src/main/java/org/springframework/jms/support/destination/DestinationResolver.java b/spring-jms/src/main/java/org/springframework/jms/support/destination/DestinationResolver.java index 4a0d2cde4e..a51d795d78 100644 --- a/spring-jms/src/main/java/org/springframework/jms/support/destination/DestinationResolver.java +++ b/spring-jms/src/main/java/org/springframework/jms/support/destination/DestinationResolver.java @@ -20,6 +20,8 @@ import javax.jms.Destination; import javax.jms.JMSException; import javax.jms.Session; +import org.springframework.lang.Nullable; + /** * Strategy interface for resolving JMS destinations. * @@ -52,7 +54,7 @@ public interface DestinationResolver { * @throws javax.jms.JMSException if the JMS Session failed to resolve the destination * @throws DestinationResolutionException in case of general destination resolution failure */ - Destination resolveDestinationName(Session session, String destinationName, boolean pubSubDomain) + Destination resolveDestinationName(@Nullable Session session, String destinationName, boolean pubSubDomain) throws JMSException; } diff --git a/spring-jms/src/main/java/org/springframework/jms/support/destination/JmsDestinationAccessor.java b/spring-jms/src/main/java/org/springframework/jms/support/destination/JmsDestinationAccessor.java index 0093f86faa..9885b66cc4 100644 --- a/spring-jms/src/main/java/org/springframework/jms/support/destination/JmsDestinationAccessor.java +++ b/spring-jms/src/main/java/org/springframework/jms/support/destination/JmsDestinationAccessor.java @@ -23,6 +23,7 @@ import javax.jms.MessageConsumer; import javax.jms.Session; import org.springframework.jms.support.JmsAccessor; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -125,6 +126,7 @@ public abstract class JmsDestinationAccessor extends JmsAccessor { * @see #RECEIVE_TIMEOUT_NO_WAIT * @see #RECEIVE_TIMEOUT_INDEFINITE_WAIT */ + @Nullable protected Message receiveFromConsumer(MessageConsumer consumer, long timeout) throws JMSException { if (timeout > 0) { return consumer.receive(timeout); diff --git a/spring-jms/src/main/java/org/springframework/jms/support/destination/package-info.java b/spring-jms/src/main/java/org/springframework/jms/support/destination/package-info.java index 16b5d900db..3326d0c704 100644 --- a/spring-jms/src/main/java/org/springframework/jms/support/destination/package-info.java +++ b/spring-jms/src/main/java/org/springframework/jms/support/destination/package-info.java @@ -1,4 +1,7 @@ /** * Support classes for Spring's JMS framework. */ +@NonNullApi package org.springframework.jms.support.destination; + +import org.springframework.lang.NonNullApi; diff --git a/spring-jms/src/main/java/org/springframework/jms/support/package-info.java b/spring-jms/src/main/java/org/springframework/jms/support/package-info.java index fd367be264..b20dce21d8 100644 --- a/spring-jms/src/main/java/org/springframework/jms/support/package-info.java +++ b/spring-jms/src/main/java/org/springframework/jms/support/package-info.java @@ -2,4 +2,7 @@ * This package provides generic JMS support classes, * to be used by higher-level classes like JmsTemplate. */ +@NonNullApi package org.springframework.jms.support; + +import org.springframework.lang.NonNullApi; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/MessageHeaders.java b/spring-messaging/src/main/java/org/springframework/messaging/MessageHeaders.java index dfce697904..e7d0b082f5 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/MessageHeaders.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/MessageHeaders.java @@ -31,6 +31,7 @@ import java.util.UUID; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.lang.Nullable; import org.springframework.util.AlternativeJdkIdGenerator; import org.springframework.util.IdGenerator; @@ -164,24 +165,29 @@ public class MessageHeaders implements Map, Serializable { return (idGenerator != null ? idGenerator : defaultIdGenerator); } + @Nullable public UUID getId() { return get(ID, UUID.class); } + @Nullable public Long getTimestamp() { return get(TIMESTAMP, Long.class); } + @Nullable public Object getReplyChannel() { return get(REPLY_CHANNEL); } + @Nullable public Object getErrorChannel() { return get(ERROR_CHANNEL); } @SuppressWarnings("unchecked") + @Nullable public T get(Object key, Class type) { Object value = this.headers.get(key); if (value == null) { @@ -209,6 +215,7 @@ public class MessageHeaders implements Map, Serializable { return Collections.unmodifiableMap(this.headers).entrySet(); } + @Nullable public Object get(Object key) { return this.headers.get(key); } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/PollableChannel.java b/spring-messaging/src/main/java/org/springframework/messaging/PollableChannel.java index eb5aafc8e2..a1861471ec 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/PollableChannel.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/PollableChannel.java @@ -16,6 +16,8 @@ package org.springframework.messaging; +import org.springframework.lang.Nullable; + /** * A {@link MessageChannel} from which messages may be actively received through polling. * @@ -28,6 +30,7 @@ public interface PollableChannel extends MessageChannel { * Receive a message from this channel, blocking indefinitely if necessary. * @return the next available {@link Message} or {@code null} if interrupted */ + @Nullable Message receive(); /** @@ -37,6 +40,7 @@ public interface PollableChannel extends MessageChannel { * @return the next available {@link Message} or {@code null} if the specified timeout * period elapses or the message reception is interrupted */ + @Nullable Message receive(long timeout); } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/converter/AbstractMessageConverter.java b/spring-messaging/src/main/java/org/springframework/messaging/converter/AbstractMessageConverter.java index 9f30bcbe48..77cac86386 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/converter/AbstractMessageConverter.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/converter/AbstractMessageConverter.java @@ -24,6 +24,7 @@ import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessageHeaders; import org.springframework.messaging.support.MessageBuilder; @@ -157,6 +158,7 @@ public abstract class AbstractMessageConverter implements SmartMessageConverter * @param payload the payload being converted to message * @return the content type, or {@code null} if not known */ + @Nullable protected MimeType getDefaultContentType(Object payload) { List mimeTypes = getSupportedMimeTypes(); return (!mimeTypes.isEmpty() ? mimeTypes.get(0) : null); @@ -255,7 +257,8 @@ public abstract class AbstractMessageConverter implements SmartMessageConverter * perform the conversion * @since 4.2 */ - protected Object convertFromInternal(Message message, Class targetClass, Object conversionHint) { + @Nullable + protected Object convertFromInternal(Message message, Class targetClass, @Nullable Object conversionHint) { return null; } @@ -269,7 +272,8 @@ public abstract class AbstractMessageConverter implements SmartMessageConverter * cannot perform the conversion * @since 4.2 */ - protected Object convertToInternal(Object payload, MessageHeaders headers, Object conversionHint) { + @Nullable + protected Object convertToInternal(Object payload, @Nullable MessageHeaders headers, @Nullable Object conversionHint) { return null; } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/converter/ContentTypeResolver.java b/spring-messaging/src/main/java/org/springframework/messaging/converter/ContentTypeResolver.java index afd7b7002c..17665b8013 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/converter/ContentTypeResolver.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/converter/ContentTypeResolver.java @@ -16,6 +16,7 @@ package org.springframework.messaging.converter; +import org.springframework.lang.Nullable; import org.springframework.messaging.MessageHeaders; import org.springframework.util.MimeType; @@ -32,13 +33,14 @@ public interface ContentTypeResolver { * Determine the {@link MimeType} of a message from the given MessageHeaders. * * @param headers the headers to use for the resolution - * @return the resolved {@code MimeType} of {@code null} if none found + * @return the resolved {@code MimeType} or {@code null} if none found * * @throws org.springframework.util.InvalidMimeTypeException if the content type * is a String that cannot be parsed * @throws java.lang.IllegalArgumentException if there is a content type but * its type is unknown */ + @Nullable MimeType resolve(MessageHeaders headers); } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/converter/MappingJackson2MessageConverter.java b/spring-messaging/src/main/java/org/springframework/messaging/converter/MappingJackson2MessageConverter.java index 7535a4139a..9b47869158 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/converter/MappingJackson2MessageConverter.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/converter/MappingJackson2MessageConverter.java @@ -38,6 +38,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; import org.springframework.core.MethodParameter; +import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessageHeaders; import org.springframework.util.Assert; @@ -266,6 +267,7 @@ public class MappingJackson2MessageConverter extends AbstractMessageConverter { * @return the serialization view class, or {@code null} if none * @since 4.2 */ + @Nullable protected Class getSerializationView(Object conversionHint) { if (conversionHint instanceof MethodParameter) { MethodParameter param = (MethodParameter) conversionHint; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/converter/MessageConverter.java b/spring-messaging/src/main/java/org/springframework/messaging/converter/MessageConverter.java index d86ee9fe2f..8bd848e5f4 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/converter/MessageConverter.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/converter/MessageConverter.java @@ -16,6 +16,7 @@ package org.springframework.messaging.converter; +import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessageHeaders; @@ -41,6 +42,7 @@ public interface MessageConverter { * @return the result of the conversion, or {@code null} if the converter cannot * perform the conversion */ + @Nullable Object fromMessage(Message message, Class targetClass); /** @@ -56,6 +58,7 @@ public interface MessageConverter { * @return the new message, or {@code null} if the converter does not support the * Object type or the target media type */ - Message toMessage(Object payload, MessageHeaders headers); + @Nullable + Message toMessage(Object payload, @Nullable MessageHeaders headers); } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/converter/SmartMessageConverter.java b/spring-messaging/src/main/java/org/springframework/messaging/converter/SmartMessageConverter.java index f36f2ac68f..f3b4cbcd4a 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/converter/SmartMessageConverter.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/converter/SmartMessageConverter.java @@ -16,6 +16,7 @@ package org.springframework.messaging.converter; +import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessageHeaders; @@ -43,7 +44,8 @@ public interface SmartMessageConverter extends MessageConverter { * perform the conversion * @see #fromMessage(Message, Class) */ - Object fromMessage(Message message, Class targetClass, Object conversionHint); + @Nullable + Object fromMessage(Message message, Class targetClass, @Nullable Object conversionHint); /** * A variant of {@link #toMessage(Object, MessageHeaders)} which takes an extra @@ -57,6 +59,7 @@ public interface SmartMessageConverter extends MessageConverter { * Object type or the target media type * @see #toMessage(Object, MessageHeaders) */ - Message toMessage(Object payload, MessageHeaders headers, Object conversionHint); + @Nullable + Message toMessage(Object payload, @Nullable MessageHeaders headers, @Nullable Object conversionHint); } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/converter/package-info.java b/spring-messaging/src/main/java/org/springframework/messaging/converter/package-info.java index ff66959a6b..26d62314c2 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/converter/package-info.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/converter/package-info.java @@ -1,4 +1,7 @@ /** * Provides support for message conversion. */ +@NonNullApi package org.springframework.messaging.converter; + +import org.springframework.lang.NonNullApi; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/core/AbstractMessageReceivingTemplate.java b/spring-messaging/src/main/java/org/springframework/messaging/core/AbstractMessageReceivingTemplate.java index 56e85c9925..09f757fe08 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/core/AbstractMessageReceivingTemplate.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/core/AbstractMessageReceivingTemplate.java @@ -16,6 +16,7 @@ package org.springframework.messaging.core; +import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.converter.MessageConversionException; import org.springframework.messaging.converter.MessageConverter; @@ -48,6 +49,7 @@ public abstract class AbstractMessageReceivingTemplate extends AbstractMessag * @return the received message, possibly {@code null} if the message could not * be received, for example due to a timeout */ + @Nullable protected abstract Message doReceive(D destination); @@ -74,6 +76,7 @@ public abstract class AbstractMessageReceivingTemplate extends AbstractMessag * @return the converted payload of the reply message (never {@code null}) */ @SuppressWarnings("unchecked") + @Nullable protected T doConvert(Message message, Class targetClass) { MessageConverter messageConverter = getMessageConverter(); T value = (T) messageConverter.fromMessage(message, targetClass); diff --git a/spring-messaging/src/main/java/org/springframework/messaging/core/AbstractMessageSendingTemplate.java b/spring-messaging/src/main/java/org/springframework/messaging/core/AbstractMessageSendingTemplate.java index 2475de7fd7..0fa76798a6 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/core/AbstractMessageSendingTemplate.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/core/AbstractMessageSendingTemplate.java @@ -21,6 +21,7 @@ import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessageHeaders; import org.springframework.messaging.MessagingException; @@ -189,7 +190,8 @@ public abstract class AbstractMessageSendingTemplate implements MessageSendin * @param headers the headers to send (or {@code null} if none) * @return the actual headers to send (or {@code null} if none) */ - protected Map processHeadersToSend(Map headers) { + @Nullable + protected Map processHeadersToSend(@Nullable Map headers) { return headers; } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/core/DestinationResolvingMessageRequestReplyOperations.java b/spring-messaging/src/main/java/org/springframework/messaging/core/DestinationResolvingMessageRequestReplyOperations.java index 4c4a89f4f3..4b8d2ca5d8 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/core/DestinationResolvingMessageRequestReplyOperations.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/core/DestinationResolvingMessageRequestReplyOperations.java @@ -18,6 +18,7 @@ package org.springframework.messaging.core; import java.util.Map; +import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessagingException; @@ -40,6 +41,7 @@ public interface DestinationResolvingMessageRequestReplyOperations extends Me * @return the received message, possibly {@code null} if the message could not * be received, for example due to a timeout */ + @Nullable Message sendAndReceive(String destinationName, Message requestMessage) throws MessagingException; /** @@ -54,6 +56,7 @@ public interface DestinationResolvingMessageRequestReplyOperations extends Me * @return the converted payload of the reply message, possibly {@code null} if * the message could not be received, for example due to a timeout */ + @Nullable T convertSendAndReceive(String destinationName, Object request, Class targetClass) throws MessagingException; @@ -70,6 +73,7 @@ public interface DestinationResolvingMessageRequestReplyOperations extends Me * @return the converted payload of the reply message, possibly {@code null} if * the message could not be received, for example due to a timeout */ + @Nullable T convertSendAndReceive(String destinationName, Object request, Map headers, Class targetClass) throws MessagingException; @@ -87,6 +91,7 @@ public interface DestinationResolvingMessageRequestReplyOperations extends Me * @return the converted payload of the reply message, possibly {@code null} if * the message could not be received, for example due to a timeout */ + @Nullable T convertSendAndReceive(String destinationName, Object request, Class targetClass, MessagePostProcessor requestPostProcessor) throws MessagingException; @@ -105,6 +110,7 @@ public interface DestinationResolvingMessageRequestReplyOperations extends Me * @return the converted payload of the reply message, possibly {@code null} if * the message could not be received, for example due to a timeout */ + @Nullable T convertSendAndReceive(String destinationName, Object request, Map headers, Class targetClass, MessagePostProcessor requestPostProcessor) throws MessagingException; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/core/MessageReceivingOperations.java b/spring-messaging/src/main/java/org/springframework/messaging/core/MessageReceivingOperations.java index d9bf600b72..ba15873157 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/core/MessageReceivingOperations.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/core/MessageReceivingOperations.java @@ -16,6 +16,7 @@ package org.springframework.messaging.core; +import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessagingException; @@ -35,6 +36,7 @@ public interface MessageReceivingOperations { * @return the received message, possibly {@code null} if the message could not * be received, for example due to a timeout */ + @Nullable Message receive() throws MessagingException; /** @@ -43,6 +45,7 @@ public interface MessageReceivingOperations { * @return the received message, possibly {@code null} if the message could not * be received, for example due to a timeout */ + @Nullable Message receive(D destination) throws MessagingException; /** @@ -52,6 +55,7 @@ public interface MessageReceivingOperations { * @return the converted payload of the reply message, possibly {@code null} if * the message could not be received, for example due to a timeout */ + @Nullable T receiveAndConvert(Class targetClass) throws MessagingException; /** @@ -62,6 +66,7 @@ public interface MessageReceivingOperations { * @return the converted payload of the reply message, possibly {@code null} if * the message could not be received, for example due to a timeout */ + @Nullable T receiveAndConvert(D destination, Class targetClass) throws MessagingException; } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/core/MessageRequestReplyOperations.java b/spring-messaging/src/main/java/org/springframework/messaging/core/MessageRequestReplyOperations.java index 3037cb820f..c4a0c0be9a 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/core/MessageRequestReplyOperations.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/core/MessageRequestReplyOperations.java @@ -18,6 +18,7 @@ package org.springframework.messaging.core; import java.util.Map; +import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessagingException; @@ -38,6 +39,7 @@ public interface MessageRequestReplyOperations { * @return the reply, possibly {@code null} if the message could not be received, * for example due to a timeout */ + @Nullable Message sendAndReceive(Message requestMessage) throws MessagingException; /** @@ -47,6 +49,7 @@ public interface MessageRequestReplyOperations { * @return the reply, possibly {@code null} if the message could not be received, * for example due to a timeout */ + @Nullable Message sendAndReceive(D destination, Message requestMessage) throws MessagingException; /** @@ -59,6 +62,7 @@ public interface MessageRequestReplyOperations { * @return the payload of the reply message, possibly {@code null} if the message * could not be received, for example due to a timeout */ + @Nullable T convertSendAndReceive(Object request, Class targetClass) throws MessagingException; /** @@ -72,6 +76,7 @@ public interface MessageRequestReplyOperations { * @return the payload of the reply message, possibly {@code null} if the message * could not be received, for example due to a timeout */ + @Nullable T convertSendAndReceive(D destination, Object request, Class targetClass) throws MessagingException; /** @@ -86,6 +91,7 @@ public interface MessageRequestReplyOperations { * @return the payload of the reply message, possibly {@code null} if the message * could not be received, for example due to a timeout */ + @Nullable T convertSendAndReceive(D destination, Object request, Map headers, Class targetClass) throws MessagingException; @@ -101,6 +107,7 @@ public interface MessageRequestReplyOperations { * @return the payload of the reply message, possibly {@code null} if the message * could not be received, for example due to a timeout */ + @Nullable T convertSendAndReceive(Object request, Class targetClass, MessagePostProcessor requestPostProcessor) throws MessagingException; @@ -117,6 +124,7 @@ public interface MessageRequestReplyOperations { * @return the payload of the reply message, possibly {@code null} if the message * could not be received, for example due to a timeout */ + @Nullable T convertSendAndReceive(D destination, Object request, Class targetClass, MessagePostProcessor requestPostProcessor) throws MessagingException; @@ -133,6 +141,7 @@ public interface MessageRequestReplyOperations { * @return the payload of the reply message, possibly {@code null} if the message * could not be received, for example due to a timeout */ + @Nullable T convertSendAndReceive(D destination, Object request, Map headers, Class targetClass, MessagePostProcessor requestPostProcessor) throws MessagingException; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/core/package-info.java b/spring-messaging/src/main/java/org/springframework/messaging/core/package-info.java index f72acc70ea..ec6b8ec107 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/core/package-info.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/core/package-info.java @@ -1,4 +1,7 @@ /** * Defines interfaces and implementation classes for messaging templates. */ +@NonNullApi package org.springframework.messaging.core; + +import org.springframework.lang.NonNullApi; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/MessageCondition.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/MessageCondition.java index 0d4769f387..7095ee7c5a 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/MessageCondition.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/MessageCondition.java @@ -16,6 +16,7 @@ package org.springframework.messaging.handler; +import org.springframework.lang.Nullable; import org.springframework.messaging.Message; /** @@ -46,6 +47,7 @@ public interface MessageCondition { * condition with sorted, matching patterns only. * @return a condition instance in case of a match; or {@code null} if there is no match. */ + @Nullable T getMatchingCondition(Message message); /** diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/package-info.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/package-info.java index 533f25c2b2..0e46b794a6 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/package-info.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/package-info.java @@ -1,4 +1,7 @@ /** * Annotations and support classes for handling messages. */ +@NonNullApi package org.springframework.messaging.handler.annotation; + +import org.springframework.lang.NonNullApi; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/AbstractNamedValueMethodArgumentResolver.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/AbstractNamedValueMethodArgumentResolver.java index 65ac468a38..1c460b4bca 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/AbstractNamedValueMethodArgumentResolver.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/AbstractNamedValueMethodArgumentResolver.java @@ -27,6 +27,7 @@ import org.springframework.core.MethodParameter; import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.TypeDescriptor; import org.springframework.core.convert.support.DefaultConversionService; +import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.handler.annotation.ValueConstants; import org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver; @@ -75,7 +76,7 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements Handle * and {@code #{...}} SpEL expressions in default values, or {@code null} if default * values are not expected to contain expressions */ - protected AbstractNamedValueMethodArgumentResolver(ConversionService cs, ConfigurableBeanFactory beanFactory) { + protected AbstractNamedValueMethodArgumentResolver(ConversionService cs, @Nullable ConfigurableBeanFactory beanFactory) { this.conversionService = (cs != null ? cs : DefaultConversionService.getSharedInstance()); this.configurableBeanFactory = beanFactory; this.expressionContext = (beanFactory != null ? new BeanExpressionContext(beanFactory, null) : null); @@ -177,6 +178,7 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements Handle * @return the resolved argument. May be {@code null} * @throws Exception in case of errors */ + @Nullable protected abstract Object resolveArgumentInternal(MethodParameter parameter, Message message, String name) throws Exception; @@ -194,7 +196,7 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements Handle * A {@code null} results in a {@code false} value for {@code boolean}s or an * exception for other primitives. */ - private Object handleNullValue(String name, Object value, Class paramType) { + private Object handleNullValue(String name, @Nullable Object value, Class paramType) { if (value == null) { if (Boolean.TYPE.equals(paramType)) { return Boolean.FALSE; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/HeaderMethodArgumentResolver.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/HeaderMethodArgumentResolver.java index e32de6fa5e..a08db6058c 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/HeaderMethodArgumentResolver.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/HeaderMethodArgumentResolver.java @@ -25,6 +25,7 @@ import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.core.MethodParameter; import org.springframework.core.convert.ConversionService; +import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessageHandlingException; import org.springframework.messaging.handler.annotation.Header; @@ -76,6 +77,7 @@ public class HeaderMethodArgumentResolver extends AbstractNamedValueMethodArgume return (headerValue != null ? headerValue : nativeHeaderValue); } + @Nullable private Object getNativeHeaderValue(Message message, String name) { Map> nativeHeaders = getNativeHeaders(message); if (name.startsWith("nativeHeaders.")) { diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/MessageMethodArgumentResolver.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/MessageMethodArgumentResolver.java index e247cd9bd1..d1c8bc9bf1 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/MessageMethodArgumentResolver.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/MessageMethodArgumentResolver.java @@ -20,6 +20,7 @@ import java.lang.reflect.Type; import org.springframework.core.MethodParameter; import org.springframework.core.ResolvableType; +import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.converter.MessageConversionException; import org.springframework.messaging.converter.MessageConverter; @@ -57,7 +58,7 @@ public class MessageMethodArgumentResolver implements HandlerMethodArgumentResol * @param converter the MessageConverter to use (may be {@code null}) * @since 4.3 */ - public MessageMethodArgumentResolver(MessageConverter converter) { + public MessageMethodArgumentResolver(@Nullable MessageConverter converter) { this.converter = converter; } @@ -103,7 +104,7 @@ public class MessageMethodArgumentResolver implements HandlerMethodArgumentResol * Check if the given {@code payload} is empty. * @param payload the payload to check (can be {@code null}) */ - protected boolean isEmptyPayload(Object payload) { + protected boolean isEmptyPayload(@Nullable Object payload) { if (payload == null) { return true; } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/MethodArgumentNotValidException.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/MethodArgumentNotValidException.java index 37960a97da..e043070fca 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/MethodArgumentNotValidException.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/MethodArgumentNotValidException.java @@ -17,6 +17,7 @@ package org.springframework.messaging.handler.annotation.support; import org.springframework.core.MethodParameter; +import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.handler.invocation.MethodArgumentResolutionException; import org.springframework.validation.BindingResult; @@ -57,6 +58,7 @@ public class MethodArgumentNotValidException extends MethodArgumentResolutionExc * Return the BindingResult if the failure is validation-related, * or {@code null} if none. */ + @Nullable public final BindingResult getBindingResult() { return this.bindingResult; } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/PayloadArgumentResolver.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/PayloadArgumentResolver.java index 7230395243..df31202e23 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/PayloadArgumentResolver.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/PayloadArgumentResolver.java @@ -20,6 +20,7 @@ import java.lang.annotation.Annotation; import org.springframework.core.MethodParameter; import org.springframework.core.annotation.AnnotationUtils; +import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.converter.MessageConversionException; import org.springframework.messaging.converter.MessageConverter; @@ -155,7 +156,7 @@ public class PayloadArgumentResolver implements HandlerMethodArgumentResolver { * Specify if the given {@code payload} is empty. * @param payload the payload to check (can be {@code null}) */ - protected boolean isEmptyPayload(Object payload) { + protected boolean isEmptyPayload(@Nullable Object payload) { if (payload == null) { return true; } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/AbstractExceptionHandlerMethodResolver.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/AbstractExceptionHandlerMethodResolver.java index 723d7f25d9..576093ee38 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/AbstractExceptionHandlerMethodResolver.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/AbstractExceptionHandlerMethodResolver.java @@ -24,6 +24,7 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import org.springframework.core.ExceptionDepthComparator; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; @@ -84,6 +85,7 @@ public abstract class AbstractExceptionHandlerMethodResolver { * @param exception the exception * @return a Method to handle the exception, or {@code null} if none found */ + @Nullable public Method resolveMethod(Exception exception) { Method method = resolveMethodByExceptionType(exception.getClass()); if (method == null) { @@ -102,6 +104,7 @@ public abstract class AbstractExceptionHandlerMethodResolver { * @return a Method to handle the exception, or {@code null} if none found * @since 4.3.1 */ + @Nullable public Method resolveMethodByExceptionType(Class exceptionType) { Method method = this.exceptionLookupCache.get(exceptionType); if (method == null) { @@ -114,6 +117,7 @@ public abstract class AbstractExceptionHandlerMethodResolver { /** * Return the {@link Method} mapped to the given exception type, or {@code null} if none. */ + @Nullable private Method getMappedMethod(Class exceptionType) { List> matches = new ArrayList<>(); for (Class mappedException : this.mappedMethods.keySet()) { diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/AbstractMethodMessageHandler.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/AbstractMethodMessageHandler.java index fa923770d7..add2f87eb7 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/AbstractMethodMessageHandler.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/AbstractMethodMessageHandler.java @@ -35,6 +35,7 @@ import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.core.MethodIntrospector; import org.springframework.core.MethodParameter; +import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessageHandler; import org.springframework.messaging.MessagingException; @@ -304,6 +305,7 @@ public abstract class AbstractMethodMessageHandler * @param handlerType the handler type, possibly a sub-type of the method's declaring class * @return the mapping, or {@code null} if the method is not mapped */ + @Nullable protected abstract T getMappingForMethod(Method method, Class handlerType); /** @@ -409,6 +411,7 @@ public abstract class AbstractMethodMessageHandler *

    If there are no matching prefixes, return {@code null}. *

    If there are no destination prefixes, return the destination as is. */ + @Nullable protected String getLookupDestination(String destination) { if (destination == null) { return null; @@ -477,6 +480,7 @@ public abstract class AbstractMethodMessageHandler * @param message the message being handled * @return the match or {@code null} if there is no match */ + @Nullable protected abstract T getMatchingMapping(T mapping, Message message); protected void handleNoMatch(Set ts, String lookupDestination, Message message) { @@ -559,6 +563,7 @@ public abstract class AbstractMethodMessageHandler * @return a method to handle the exception, or {@code null} * @since 4.2 */ + @Nullable protected InvocableHandlerMethod getExceptionHandlerMethod(HandlerMethod handlerMethod, Exception exception) { if (logger.isDebugEnabled()) { logger.debug("Searching methods to handle " + exception.getClass().getSimpleName()); diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/AsyncHandlerMethodReturnValueHandler.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/AsyncHandlerMethodReturnValueHandler.java index 5da73ba3f6..96afc09cd0 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/AsyncHandlerMethodReturnValueHandler.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/AsyncHandlerMethodReturnValueHandler.java @@ -17,6 +17,7 @@ package org.springframework.messaging.handler.invocation; import org.springframework.core.MethodParameter; +import org.springframework.lang.Nullable; import org.springframework.util.concurrent.ListenableFuture; /** @@ -61,6 +62,7 @@ public interface AsyncHandlerMethodReturnValueHandler extends HandlerMethodRetur * @return the resulting ListenableFuture or {@code null} in which case no * further handling will be performed. */ + @Nullable ListenableFuture toListenableFuture(Object returnValue, MethodParameter returnType); } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/HandlerMethodArgumentResolver.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/HandlerMethodArgumentResolver.java index 28d6b45c16..317b1b61fe 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/HandlerMethodArgumentResolver.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/HandlerMethodArgumentResolver.java @@ -17,6 +17,7 @@ package org.springframework.messaging.handler.invocation; import org.springframework.core.MethodParameter; +import org.springframework.lang.Nullable; import org.springframework.messaging.Message; /** @@ -47,6 +48,7 @@ public interface HandlerMethodArgumentResolver { * @return the resolved argument value, or {@code null} * @throws Exception in case of errors with the preparation of argument values */ + @Nullable Object resolveArgument(MethodParameter parameter, Message message) throws Exception; } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/HandlerMethodReturnValueHandlerComposite.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/HandlerMethodReturnValueHandlerComposite.java index 99ff814643..0899d434ff 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/HandlerMethodReturnValueHandlerComposite.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/HandlerMethodReturnValueHandlerComposite.java @@ -24,6 +24,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.core.MethodParameter; +import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.util.Assert; import org.springframework.util.concurrent.ListenableFuture; @@ -80,6 +81,7 @@ public class HandlerMethodReturnValueHandlerComposite implements AsyncHandlerMet return getReturnValueHandler(returnType) != null; } + @Nullable private HandlerMethodReturnValueHandler getReturnValueHandler(MethodParameter returnType) { for (HandlerMethodReturnValueHandler handler : this.returnValueHandlers) { if (handler.supportsReturnType(returnType)) { diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/InvocableHandlerMethod.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/InvocableHandlerMethod.java index 8cab1fde98..3ab2a202e0 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/InvocableHandlerMethod.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/InvocableHandlerMethod.java @@ -25,6 +25,7 @@ import org.springframework.core.DefaultParameterNameDiscoverer; import org.springframework.core.MethodParameter; import org.springframework.core.ParameterNameDiscoverer; import org.springframework.core.ResolvableType; +import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.handler.HandlerMethod; import org.springframework.util.ClassUtils; @@ -158,6 +159,7 @@ public class InvocableHandlerMethod extends HandlerMethod { /** * Attempt to resolve a method parameter from the list of provided argument values. */ + @Nullable private Object resolveProvidedArgument(MethodParameter parameter, Object... providedArgs) { if (providedArgs == null) { return null; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/package-info.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/package-info.java index a05588b792..b1593a3fdb 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/package-info.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/package-info.java @@ -1,4 +1,7 @@ /** * Common infrastructure for invoking message handler methods. */ +@NonNullApi package org.springframework.messaging.handler.invocation; + +import org.springframework.lang.NonNullApi; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/package-info.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/package-info.java index 481a9d7fb4..e9e183387d 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/package-info.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/package-info.java @@ -1,4 +1,7 @@ /** * Basic abstractions for working with message handler methods. */ +@NonNullApi package org.springframework.messaging.handler; + +import org.springframework.lang.NonNullApi; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/package-info.java b/spring-messaging/src/main/java/org/springframework/messaging/package-info.java index 4836526c7a..bcf02caca3 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/package-info.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/package-info.java @@ -1,4 +1,7 @@ /** * Support for working with messaging APIs and protocols. */ +@NonNullApi package org.springframework.messaging; + +import org.springframework.lang.NonNullApi; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/SimpAttributes.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/SimpAttributes.java index bc50bfa146..b2f4e97e3a 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/SimpAttributes.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/SimpAttributes.java @@ -21,6 +21,7 @@ import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessageHeaders; import org.springframework.util.Assert; @@ -70,6 +71,7 @@ public class SimpAttributes { * @param name the name of the attribute * @return the current attribute value, or {@code null} if not found */ + @Nullable public Object getAttribute(String name) { return this.attributes.get(name); } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/SimpAttributesContextHolder.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/SimpAttributesContextHolder.java index 512641d2c7..d6265f7456 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/SimpAttributesContextHolder.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/SimpAttributesContextHolder.java @@ -17,6 +17,7 @@ package org.springframework.messaging.simp; import org.springframework.core.NamedThreadLocal; +import org.springframework.lang.Nullable; import org.springframework.messaging.Message; @@ -66,6 +67,7 @@ public abstract class SimpAttributesContextHolder { * Return the SimpAttributes currently bound to the thread. * @return the attributes or {@code null} if not bound */ + @Nullable public static SimpAttributes getAttributes() { return attributesHolder.get(); } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/SimpMessageSendingOperations.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/SimpMessageSendingOperations.java index 953d871560..28b6f8083f 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/SimpMessageSendingOperations.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/SimpMessageSendingOperations.java @@ -18,6 +18,7 @@ package org.springframework.messaging.simp; import java.util.Map; +import org.springframework.lang.Nullable; import org.springframework.messaging.MessagingException; import org.springframework.messaging.core.MessagePostProcessor; import org.springframework.messaging.core.MessageSendingOperations; @@ -83,7 +84,7 @@ public interface SimpMessageSendingOperations extends MessageSendingOperations headers) + void convertAndSendToUser(String user, String destination, @Nullable Object payload, @Nullable Map headers) throws MessagingException; /** @@ -93,7 +94,7 @@ public interface SimpMessageSendingOperations extends MessageSendingOperations message, MessageHeaders headers) { Principal principal = SimpMessageHeaderAccessor.getUser(headers); if (principal != null) { diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/package-info.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/package-info.java index 2cddb57e4e..c195345070 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/package-info.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/package-info.java @@ -2,4 +2,7 @@ * Support classes for handling messages from simple messaging protocols * (like STOMP). */ +@NonNullApi package org.springframework.messaging.simp.annotation.support; + +import org.springframework.lang.NonNullApi; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/DefaultSubscriptionRegistry.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/DefaultSubscriptionRegistry.java index fed76b4230..45777103db 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/DefaultSubscriptionRegistry.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/DefaultSubscriptionRegistry.java @@ -35,6 +35,7 @@ import org.springframework.expression.TypedValue; import org.springframework.expression.spel.SpelEvaluationException; import org.springframework.expression.spel.standard.SpelExpressionParser; import org.springframework.expression.spel.support.StandardEvaluationContext; +import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessageHeaders; import org.springframework.messaging.simp.SimpMessageHeaderAccessor; @@ -428,6 +429,7 @@ public class DefaultSubscriptionRegistry extends AbstractSubscriptionRegistry { return this.destinationLookup.get(destination); } + @Nullable public Subscription getSubscription(String subscriptionId) { for (Map.Entry> destinationEntry : this.destinationLookup.entrySet()) { Set subs = destinationEntry.getValue(); @@ -456,6 +458,7 @@ public class DefaultSubscriptionRegistry extends AbstractSubscriptionRegistry { subs.add(new Subscription(subscriptionId, selectorExpression)); } + @Nullable public String removeSubscription(String subscriptionId) { for (Map.Entry> destinationEntry : this.destinationLookup.entrySet()) { Set subs = destinationEntry.getValue(); diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/package-info.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/package-info.java index 46e45bb944..177abfe7a5 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/package-info.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/package-info.java @@ -2,4 +2,7 @@ * Provides a "simple" message broker implementation along with an abstract base * class and other supporting types such as a registry for subscriptions. */ +@NonNullApi package org.springframework.messaging.simp.broker; + +import org.springframework.lang.NonNullApi; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/config/AbstractMessageBrokerConfiguration.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/config/AbstractMessageBrokerConfiguration.java index 95c483c66d..6730886357 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/config/AbstractMessageBrokerConfiguration.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/config/AbstractMessageBrokerConfiguration.java @@ -26,6 +26,7 @@ import org.springframework.beans.factory.BeanInitializationException; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.context.annotation.Bean; +import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessageHandler; import org.springframework.messaging.converter.ByteArrayMessageConverter; @@ -447,6 +448,7 @@ public abstract class AbstractMessageBrokerConfiguration implements ApplicationC * Override this method to provide a custom {@link Validator}. * @since 4.0.1 */ + @Nullable public Validator getValidator() { return null; } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/config/MessageBrokerRegistry.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/config/MessageBrokerRegistry.java index 5267b0ffff..9dd0dd8550 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/config/MessageBrokerRegistry.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/config/MessageBrokerRegistry.java @@ -19,6 +19,7 @@ package org.springframework.messaging.simp.config; import java.util.Arrays; import java.util.Collection; +import org.springframework.lang.Nullable; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.SubscribableChannel; import org.springframework.messaging.simp.broker.SimpleBrokerMessageHandler; @@ -188,6 +189,7 @@ public class MessageBrokerRegistry { } + @Nullable protected SimpleBrokerMessageHandler getSimpleBroker(SubscribableChannel brokerChannel) { if (this.simpleBrokerRegistration == null && this.brokerRelayRegistration == null) { enableSimpleBroker(); @@ -201,6 +203,7 @@ public class MessageBrokerRegistry { return null; } + @Nullable protected StompBrokerRelayMessageHandler getStompBrokerRelay(SubscribableChannel brokerChannel) { if (this.brokerRelayRegistration != null) { return this.brokerRelayRegistration.getMessageHandler(brokerChannel); diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/config/package-info.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/config/package-info.java index b679aa38bb..856966dc0e 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/config/package-info.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/config/package-info.java @@ -1,4 +1,7 @@ /** * Configuration support for WebSocket messaging using higher level messaging protocols. */ +@NonNullApi package org.springframework.messaging.simp.config; + +import org.springframework.lang.NonNullApi; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/package-info.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/package-info.java index 343b07c30e..b9f3ef39bd 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/package-info.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/package-info.java @@ -1,4 +1,7 @@ /** * Generic support for SImple Messaging Protocols including protocols such as STOMP. */ +@NonNullApi package org.springframework.messaging.simp; + +import org.springframework.lang.NonNullApi; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompDecoder.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompDecoder.java index d7ab7a80ae..b97f73d045 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompDecoder.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompDecoder.java @@ -26,6 +26,7 @@ import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.support.MessageBuilder; import org.springframework.messaging.support.MessageHeaderInitializer; @@ -66,6 +67,7 @@ public class StompDecoder { /** * Return the configured {@code MessageHeaderInitializer}, if any. */ + @Nullable public MessageHeaderInitializer getHeaderInitializer() { return this.headerInitializer; } @@ -80,6 +82,7 @@ public class StompDecoder { * @return the decoded messages, or an empty list if none * @throws StompConversionException raised in case of decoding issues */ + @Nullable public List> decode(ByteBuffer byteBuffer) { return decode(byteBuffer, null); } @@ -285,6 +288,7 @@ public class StompDecoder { return sb.toString(); } + @Nullable private byte[] readPayload(ByteBuffer byteBuffer, StompHeaderAccessor headerAccessor) { Integer contentLength; try { diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompFrameHandler.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompFrameHandler.java index fc2f98c548..d1968c1520 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompFrameHandler.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompFrameHandler.java @@ -18,6 +18,8 @@ package org.springframework.messaging.simp.stomp; import java.lang.reflect.Type; +import org.springframework.lang.Nullable; + /** * Contract to handle a STOMP frame. * @@ -39,6 +41,6 @@ public interface StompFrameHandler { * @param headers the headers of the frame * @param payload the payload or {@code null} if there was no payload */ - void handleFrame(StompHeaders headers, Object payload); + void handleFrame(StompHeaders headers, @Nullable Object payload); } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompHeaderAccessor.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompHeaderAccessor.java index d135257eb7..2dc707db95 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompHeaderAccessor.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompHeaderAccessor.java @@ -25,6 +25,7 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.atomic.AtomicLong; +import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.simp.SimpMessageHeaderAccessor; import org.springframework.messaging.simp.SimpMessageType; @@ -219,6 +220,7 @@ public class StompHeaderAccessor extends SimpMessageHeaderAccessor { /** * Return the STOMP command, or {@code null} if not yet set. */ + @Nullable public StompCommand getCommand() { return (StompCommand) getHeader(COMMAND_HEADER); } @@ -286,6 +288,7 @@ public class StompHeaderAccessor extends SimpMessageHeaderAccessor { } } + @Nullable public Integer getContentLength() { if (containsNativeHeader(STOMP_CONTENT_LENGTH_HEADER)) { return Integer.valueOf(getFirstNativeHeader(STOMP_CONTENT_LENGTH_HEADER)); @@ -341,6 +344,7 @@ public class StompHeaderAccessor extends SimpMessageHeaderAccessor { /** * Return the passcode header value, or {@code null} if not set. */ + @Nullable public String getPasscode() { StompPasscode credentials = (StompPasscode) getHeader(CREDENTIALS_HEADER); return (credentials != null ? credentials.passcode : null); @@ -490,6 +494,7 @@ public class StompHeaderAccessor extends SimpMessageHeaderAccessor { /** * Return the STOMP command from the given headers, or {@code null} if not set. */ + @Nullable public static StompCommand getCommand(Map headers) { return (StompCommand) headers.get(COMMAND_HEADER); } @@ -497,6 +502,7 @@ public class StompHeaderAccessor extends SimpMessageHeaderAccessor { /** * Return the passcode header value, or {@code null} if not set. */ + @Nullable public static String getPasscode(Map headers) { StompPasscode credentials = (StompPasscode) headers.get(CREDENTIALS_HEADER); return (credentials != null ? credentials.passcode : null); diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompSession.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompSession.java index b348da11a3..ef2a8563c4 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompSession.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompSession.java @@ -16,6 +16,8 @@ package org.springframework.messaging.simp.stomp; +import org.springframework.lang.Nullable; + /** * Represents a STOMP session with operations to send messages, create * subscriptions and receive messages on those subscriptions. @@ -115,6 +117,7 @@ public interface StompSession { * Return the receipt id, or {@code null} if the STOMP frame for which * the handle was returned did not have a "receipt" header. */ + @Nullable String getReceiptId(); /** diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/package-info.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/package-info.java index df73ffeb65..44ea22128b 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/package-info.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/package-info.java @@ -1,4 +1,7 @@ /** * Generic support for simple messaging protocols (like STOMP). */ +@NonNullApi package org.springframework.messaging.simp.stomp; + +import org.springframework.lang.NonNullApi; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/user/DefaultUserDestinationResolver.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/user/DefaultUserDestinationResolver.java index 291fc585e7..a7193e8e86 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/user/DefaultUserDestinationResolver.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/user/DefaultUserDestinationResolver.java @@ -24,6 +24,7 @@ import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessageHeaders; import org.springframework.messaging.simp.SimpMessageHeaderAccessor; @@ -138,6 +139,7 @@ public class DefaultUserDestinationResolver implements UserDestinationResolver { return new UserDestinationResult(sourceDestination, targetSet, subscribeDestination, user); } + @Nullable private ParseResult parse(Message message) { MessageHeaders headers = message.getHeaders(); String destination = SimpMessageHeaderAccessor.getDestination(headers); @@ -215,8 +217,9 @@ public class DefaultUserDestinationResolver implements UserDestinationResolver { * @return a target destination, or {@code null} if none */ @SuppressWarnings("unused") + @Nullable protected String getTargetDestination(String sourceDestination, String actualDestination, - String sessionId, String user) { + String sessionId, @Nullable String user) { return actualDestination + "-user" + sessionId; } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/user/SimpUser.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/user/SimpUser.java index fd3a1806d2..c1de43b77c 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/user/SimpUser.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/user/SimpUser.java @@ -18,6 +18,8 @@ package org.springframework.messaging.simp.user; import java.util.Set; +import org.springframework.lang.Nullable; + /** * Represents a connected user. * @@ -39,8 +41,9 @@ public interface SimpUser { /** * Look up the session for the given id. * @param sessionId the session id - * @return the matching session of {@code null}. + * @return the matching session or {@code null}. */ + @Nullable SimpSession getSession(String sessionId); /** diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/user/SimpUserRegistry.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/user/SimpUserRegistry.java index ea5f9ab342..f1aba53c19 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/user/SimpUserRegistry.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/user/SimpUserRegistry.java @@ -18,6 +18,8 @@ package org.springframework.messaging.simp.user; import java.util.Set; +import org.springframework.lang.Nullable; + /** * A registry of currently connected users. * @@ -31,6 +33,7 @@ public interface SimpUserRegistry { * @param userName the name of the user to look up * @return the user, or {@code null} if not connected */ + @Nullable SimpUser getUser(String userName); /** diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/user/UserDestinationMessageHandler.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/user/UserDestinationMessageHandler.java index 77a3528983..9d8783e5de 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/user/UserDestinationMessageHandler.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/user/UserDestinationMessageHandler.java @@ -23,6 +23,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.context.SmartLifecycle; +import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessageHandler; import org.springframework.messaging.MessageHeaders; @@ -253,6 +254,7 @@ public class UserDestinationMessageHandler implements MessageHandler, SmartLifec return this.broadcastDestination; } + @Nullable public Message preHandle(Message message) throws MessagingException { String destination = SimpMessageHeaderAccessor.getDestination(message.getHeaders()); if (!getBroadcastDestination().equals(destination)) { diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/user/UserDestinationResolver.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/user/UserDestinationResolver.java index 722067611a..a79aec5a8a 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/user/UserDestinationResolver.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/user/UserDestinationResolver.java @@ -16,6 +16,7 @@ package org.springframework.messaging.simp.user; +import org.springframework.lang.Nullable; import org.springframework.messaging.Message; /** @@ -44,6 +45,7 @@ public interface UserDestinationResolver { * @return 0 or more target messages (one for each active session), or * {@code null} if the source message does not contain a user destination. */ + @Nullable UserDestinationResult resolveDestination(Message message); } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/user/UserDestinationResult.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/user/UserDestinationResult.java index 7e2d8503e6..1c9ce376ed 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/user/UserDestinationResult.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/user/UserDestinationResult.java @@ -18,6 +18,7 @@ package org.springframework.messaging.simp.user; import java.util.Set; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -89,6 +90,7 @@ public class UserDestinationResult { * sessionId in place of a user name thus removing the need for a user-to-session * lookup via {@link SimpUserRegistry}. */ + @Nullable public String getUser() { return this.user; } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/user/package-info.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/user/package-info.java index 9cf68e1459..cea4c996bb 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/user/package-info.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/user/package-info.java @@ -6,4 +6,7 @@ *

    Also included is {@link org.springframework.messaging.simp.user.SimpUserRegistry} * for keeping track of connected user sessions. */ +@NonNullApi package org.springframework.messaging.simp.user; + +import org.springframework.lang.NonNullApi; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/support/AbstractHeaderMapper.java b/spring-messaging/src/main/java/org/springframework/messaging/support/AbstractHeaderMapper.java index 5d9b4d9415..3503c6e8f9 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/support/AbstractHeaderMapper.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/support/AbstractHeaderMapper.java @@ -21,6 +21,7 @@ import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.lang.Nullable; import org.springframework.messaging.MessageHeaders; import org.springframework.util.StringUtils; @@ -88,6 +89,7 @@ public abstract class AbstractHeaderMapper implements HeaderMapper { * Return the header value, or {@code null} if it does not exist * or does not match the requested {@code type}. */ + @Nullable protected V getHeaderIfAvailable(Map headers, String name, Class type) { Object value = headers.get(name); if (value == null) { diff --git a/spring-messaging/src/main/java/org/springframework/messaging/support/AbstractMessageChannel.java b/spring-messaging/src/main/java/org/springframework/messaging/support/AbstractMessageChannel.java index 0f48b50fe4..58444f77d0 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/support/AbstractMessageChannel.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/support/AbstractMessageChannel.java @@ -24,6 +24,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.BeanNameAware; +import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.MessageDeliveryException; @@ -152,6 +153,7 @@ public abstract class AbstractMessageChannel implements MessageChannel, Intercep private int receiveInterceptorIndex = -1; + @Nullable public Message applyPreSend(Message message, MessageChannel channel) { Message messageToUse = message; for (ChannelInterceptor interceptor : interceptors) { @@ -199,6 +201,7 @@ public abstract class AbstractMessageChannel implements MessageChannel, Intercep return true; } + @Nullable public Message applyPostReceive(Message message, MessageChannel channel) { for (ChannelInterceptor interceptor : interceptors) { message = interceptor.postReceive(message, channel); diff --git a/spring-messaging/src/main/java/org/springframework/messaging/support/ChannelInterceptor.java b/spring-messaging/src/main/java/org/springframework/messaging/support/ChannelInterceptor.java index fb28d1bbad..5e85cc494f 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/support/ChannelInterceptor.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/support/ChannelInterceptor.java @@ -16,6 +16,7 @@ package org.springframework.messaging.support; +import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; @@ -36,6 +37,7 @@ public interface ChannelInterceptor { * If this method returns {@code null} then the actual * send invocation will not occur. */ + @Nullable Message preSend(Message message, MessageChannel channel); /** diff --git a/spring-messaging/src/main/java/org/springframework/messaging/support/ExecutorChannelInterceptor.java b/spring-messaging/src/main/java/org/springframework/messaging/support/ExecutorChannelInterceptor.java index cb6b993678..3300e505b2 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/support/ExecutorChannelInterceptor.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/support/ExecutorChannelInterceptor.java @@ -16,6 +16,7 @@ package org.springframework.messaging.support; +import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.MessageHandler; @@ -42,6 +43,7 @@ public interface ExecutorChannelInterceptor extends ChannelInterceptor { * @param handler the target handler to handle the message * @return the input message, or a new instance, or {@code null} */ + @Nullable Message beforeHandle(Message message, MessageChannel channel, MessageHandler handler); /** diff --git a/spring-messaging/src/main/java/org/springframework/messaging/support/ExecutorSubscribableChannel.java b/spring-messaging/src/main/java/org/springframework/messaging/support/ExecutorSubscribableChannel.java index 75db991989..8aaa06c45f 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/support/ExecutorSubscribableChannel.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/support/ExecutorSubscribableChannel.java @@ -20,6 +20,7 @@ import java.util.ArrayList; import java.util.List; import java.util.concurrent.Executor; +import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessageDeliveryException; import org.springframework.messaging.MessageHandler; @@ -54,7 +55,7 @@ public class ExecutorSubscribableChannel extends AbstractSubscribableChannel { * @param executor the executor used to send the message, * or {@code null} to execute in the callers thread. */ - public ExecutorSubscribableChannel(Executor executor) { + public ExecutorSubscribableChannel(@Nullable Executor executor) { this.executor = executor; } @@ -151,6 +152,7 @@ public class ExecutorSubscribableChannel extends AbstractSubscribableChannel { } } + @Nullable private Message applyBeforeHandle(Message message) { for (ExecutorChannelInterceptor interceptor : executorInterceptors) { message = interceptor.beforeHandle(message, ExecutorSubscribableChannel.this, this.messageHandler); diff --git a/spring-messaging/src/main/java/org/springframework/messaging/support/IdTimestampMessageHeaderInitializer.java b/spring-messaging/src/main/java/org/springframework/messaging/support/IdTimestampMessageHeaderInitializer.java index b21d7d9776..526981200b 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/support/IdTimestampMessageHeaderInitializer.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/support/IdTimestampMessageHeaderInitializer.java @@ -18,6 +18,7 @@ package org.springframework.messaging.support; import java.util.UUID; +import org.springframework.lang.Nullable; import org.springframework.messaging.MessageHeaders; import org.springframework.util.IdGenerator; @@ -57,6 +58,7 @@ public class IdTimestampMessageHeaderInitializer implements MessageHeaderInitial /** * Return the configured {@code IdGenerator}, if any. */ + @Nullable public IdGenerator getIdGenerator() { return this.idGenerator; } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/support/MessageBuilder.java b/spring-messaging/src/main/java/org/springframework/messaging/support/MessageBuilder.java index c198748eef..615db54474 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/support/MessageBuilder.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/support/MessageBuilder.java @@ -18,6 +18,7 @@ package org.springframework.messaging.support; import java.util.Map; +import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.MessageHeaders; @@ -73,7 +74,7 @@ public final class MessageBuilder { * Set the value for the given header name. If the provided value is {@code null}, * the header will be removed. */ - public MessageBuilder setHeader(String headerName, Object headerValue) { + public MessageBuilder setHeader(String headerName, @Nullable Object headerValue) { this.headerAccessor.setHeader(headerName, headerValue); return this; } @@ -187,7 +188,7 @@ public final class MessageBuilder { * @since 4.1 */ @SuppressWarnings("unchecked") - public static Message createMessage(T payload, MessageHeaders messageHeaders) { + public static Message createMessage(@Nullable T payload, MessageHeaders messageHeaders) { Assert.notNull(payload, "Payload must not be null"); Assert.notNull(messageHeaders, "MessageHeaders must not be null"); if (payload instanceof Throwable) { diff --git a/spring-messaging/src/main/java/org/springframework/messaging/support/MessageHeaderAccessor.java b/spring-messaging/src/main/java/org/springframework/messaging/support/MessageHeaderAccessor.java index 07be82ad60..da6ab0043c 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/support/MessageHeaderAccessor.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/support/MessageHeaderAccessor.java @@ -25,6 +25,7 @@ import java.util.List; import java.util.Map; import java.util.UUID; +import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.MessageHeaders; @@ -143,7 +144,7 @@ public class MessageHeaderAccessor { * A constructor accepting the headers of an existing message to copy. * @param message a message to copy the headers from, or {@code null} if none */ - public MessageHeaderAccessor(Message message) { + public MessageHeaderAccessor(@Nullable Message message) { this.headers = new MutableMessageHeaders(message != null ? message.getHeaders() : null); } @@ -284,6 +285,7 @@ public class MessageHeaderAccessor { * @param headerName the name of the header * @return the associated value, or {@code null} if none found */ + @Nullable public Object getHeader(String headerName) { return this.headers.get(headerName); } @@ -292,7 +294,7 @@ public class MessageHeaderAccessor { * Set the value for the given header name. *

    If the provided value is {@code null}, the header will be removed. */ - public void setHeader(String name, Object value) { + public void setHeader(String name, @Nullable Object value) { if (isReadOnly(name)) { throw new IllegalArgumentException("'" + name + "' header is read-only"); } @@ -414,6 +416,7 @@ public class MessageHeaderAccessor { // Specific header accessors + @Nullable public UUID getId() { Object value = getHeader(MessageHeaders.ID); if (value == null) { @@ -422,6 +425,7 @@ public class MessageHeaderAccessor { return (value instanceof UUID ? (UUID) value : UUID.fromString(value.toString())); } + @Nullable public Long getTimestamp() { Object value = getHeader(MessageHeaders.TIMESTAMP); if (value == null) { @@ -434,6 +438,7 @@ public class MessageHeaderAccessor { setHeader(MessageHeaders.CONTENT_TYPE, contentType); } + @Nullable public MimeType getContentType() { Object value = getHeader(MessageHeaders.CONTENT_TYPE); if (value == null) { @@ -561,6 +566,7 @@ public class MessageHeaderAccessor { * @return an accessor instance of the specified type, or {@code null} if none * @since 4.1 */ + @Nullable public static T getAccessor(Message message, Class requiredType) { return getAccessor(message.getHeaders(), requiredType); } @@ -573,6 +579,7 @@ public class MessageHeaderAccessor { * @since 4.1 */ @SuppressWarnings("unchecked") + @Nullable public static T getAccessor( MessageHeaders messageHeaders, Class requiredType) { diff --git a/spring-messaging/src/main/java/org/springframework/messaging/support/NativeMessageHeaderAccessor.java b/spring-messaging/src/main/java/org/springframework/messaging/support/NativeMessageHeaderAccessor.java index 3d706005d3..b31a14415d 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/support/NativeMessageHeaderAccessor.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/support/NativeMessageHeaderAccessor.java @@ -21,6 +21,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; +import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; @@ -62,7 +63,7 @@ public class NativeMessageHeaderAccessor extends MessageHeaderAccessor { * A protected constructor to create new headers. * @param nativeHeaders native headers to create the message with (may be {@code null}) */ - protected NativeMessageHeaderAccessor(Map> nativeHeaders) { + protected NativeMessageHeaderAccessor(@Nullable Map> nativeHeaders) { if (!CollectionUtils.isEmpty(nativeHeaders)) { setHeader(NATIVE_HEADERS, new LinkedMultiValueMap<>(nativeHeaders)); } @@ -121,14 +122,16 @@ public class NativeMessageHeaderAccessor extends MessageHeaderAccessor { /** * @return all values for the specified native header or {@code null}. */ + @Nullable public List getNativeHeader(String headerName) { Map> map = getNativeHeaders(); return (map != null ? map.get(headerName) : null); } /** - * @return the first value for the specified native header of {@code null}. + * @return the first value for the specified native header or {@code null}. */ + @Nullable public String getFirstNativeHeader(String headerName) { Map> map = getNativeHeaders(); if (map != null) { @@ -198,6 +201,7 @@ public class NativeMessageHeaderAccessor extends MessageHeaderAccessor { } } + @Nullable public List removeNativeHeader(String name) { Assert.state(isMutable(), "Already immutable"); Map> nativeHeaders = getNativeHeaders(); @@ -208,6 +212,7 @@ public class NativeMessageHeaderAccessor extends MessageHeaderAccessor { } @SuppressWarnings("unchecked") + @Nullable public static String getFirstNativeHeader(String headerName, Map headers) { Map> map = (Map>) headers.get(NATIVE_HEADERS); if (map != null) { diff --git a/spring-messaging/src/main/java/org/springframework/messaging/support/package-info.java b/spring-messaging/src/main/java/org/springframework/messaging/support/package-info.java index 2d62461fde..4b3967dccf 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/support/package-info.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/support/package-info.java @@ -4,4 +4,7 @@ * message headers, as well as various {@link org.springframework.messaging.MessageChannel} * implementations and channel interceptor support. */ +@NonNullApi package org.springframework.messaging.support; + +import org.springframework.lang.NonNullApi; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/tcp/ReconnectStrategy.java b/spring-messaging/src/main/java/org/springframework/messaging/tcp/ReconnectStrategy.java index e5a6c4fe18..33ea377d55 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/tcp/ReconnectStrategy.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/tcp/ReconnectStrategy.java @@ -16,6 +16,8 @@ package org.springframework.messaging.tcp; +import org.springframework.lang.Nullable; + /** * A contract to determine the frequency of reconnect attempts after connection failure. * @@ -30,6 +32,7 @@ public interface ReconnectStrategy { * @param attemptCount how many reconnect attempts have been made already * @return the amount of time in milliseconds or {@code null} to stop */ + @Nullable Long getTimeToNextAttempt(int attemptCount); } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/tcp/package-info.java b/spring-messaging/src/main/java/org/springframework/messaging/tcp/package-info.java index 4e13d2e88c..736265af22 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/tcp/package-info.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/tcp/package-info.java @@ -6,4 +6,7 @@ * as well as sending messages via * {@link org.springframework.messaging.tcp.TcpConnection TcpConnection}. */ +@NonNullApi package org.springframework.messaging.tcp; + +import org.springframework.lang.NonNullApi; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/tcp/reactor/package-info.java b/spring-messaging/src/main/java/org/springframework/messaging/tcp/reactor/package-info.java index e80e0a4c94..0d7ef61f3f 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/tcp/reactor/package-info.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/tcp/reactor/package-info.java @@ -1,4 +1,7 @@ /** * Contains support for TCP messaging based on Reactor. */ +@NonNullApi package org.springframework.messaging.tcp.reactor; + +import org.springframework.lang.NonNullApi; diff --git a/spring-orm/src/main/java/org/springframework/orm/hibernate5/HibernateCallback.java b/spring-orm/src/main/java/org/springframework/orm/hibernate5/HibernateCallback.java index d9a836db6d..6af5f1f313 100644 --- a/spring-orm/src/main/java/org/springframework/orm/hibernate5/HibernateCallback.java +++ b/spring-orm/src/main/java/org/springframework/orm/hibernate5/HibernateCallback.java @@ -19,6 +19,8 @@ package org.springframework.orm.hibernate5; import org.hibernate.HibernateException; import org.hibernate.Session; +import org.springframework.lang.Nullable; + /** * Callback interface for Hibernate code. To be used with {@link HibernateTemplate}'s * execution methods, often as anonymous classes within a method implementation. @@ -46,6 +48,7 @@ public interface HibernateCallback { * @throws HibernateException if thrown by the Hibernate API * @see HibernateTemplate#execute */ + @Nullable T doInHibernate(Session session) throws HibernateException; } diff --git a/spring-orm/src/main/java/org/springframework/orm/hibernate5/HibernateOperations.java b/spring-orm/src/main/java/org/springframework/orm/hibernate5/HibernateOperations.java index d3ae8d7f0b..08f0baa2d0 100644 --- a/spring-orm/src/main/java/org/springframework/orm/hibernate5/HibernateOperations.java +++ b/spring-orm/src/main/java/org/springframework/orm/hibernate5/HibernateOperations.java @@ -27,6 +27,7 @@ import org.hibernate.ReplicationMode; import org.hibernate.criterion.DetachedCriteria; import org.springframework.dao.DataAccessException; +import org.springframework.lang.Nullable; /** * Interface that specifies a basic set of Hibernate operations, @@ -64,6 +65,7 @@ public interface HibernateOperations { * @see HibernateTransactionManager * @see org.hibernate.Session */ + @Nullable T execute(HibernateCallback action) throws DataAccessException; @@ -84,6 +86,7 @@ public interface HibernateOperations { * @throws DataAccessException in case of Hibernate errors * @see org.hibernate.Session#get(Class, Serializable) */ + @Nullable T get(Class entityClass, Serializable id) throws DataAccessException; /** @@ -101,6 +104,7 @@ public interface HibernateOperations { * @throws DataAccessException in case of Hibernate errors * @see org.hibernate.Session#get(Class, Serializable, LockMode) */ + @Nullable T get(Class entityClass, Serializable id, LockMode lockMode) throws DataAccessException; /** @@ -116,6 +120,7 @@ public interface HibernateOperations { * @throws DataAccessException in case of Hibernate errors * @see org.hibernate.Session#get(Class, Serializable) */ + @Nullable Object get(String entityName, Serializable id) throws DataAccessException; /** @@ -133,6 +138,7 @@ public interface HibernateOperations { * @throws DataAccessException in case of Hibernate errors * @see org.hibernate.Session#get(Class, Serializable, LockMode) */ + @Nullable Object get(String entityName, Serializable id, LockMode lockMode) throws DataAccessException; /** diff --git a/spring-orm/src/main/java/org/springframework/orm/hibernate5/HibernateTemplate.java b/spring-orm/src/main/java/org/springframework/orm/hibernate5/HibernateTemplate.java index b671231f7f..df5f1bdee9 100644 --- a/spring-orm/src/main/java/org/springframework/orm/hibernate5/HibernateTemplate.java +++ b/spring-orm/src/main/java/org/springframework/orm/hibernate5/HibernateTemplate.java @@ -24,6 +24,7 @@ import java.lang.reflect.Proxy; import java.util.Collection; import java.util.Iterator; import java.util.List; + import javax.persistence.PersistenceException; import org.apache.commons.logging.Log; @@ -44,6 +45,7 @@ import org.hibernate.criterion.Example; import org.springframework.beans.factory.InitializingBean; import org.springframework.dao.DataAccessException; import org.springframework.dao.InvalidDataAccessApiUsageException; +import org.springframework.lang.Nullable; import org.springframework.transaction.support.TransactionSynchronizationManager; import org.springframework.util.Assert; import org.springframework.util.ReflectionUtils; @@ -170,6 +172,7 @@ public class HibernateTemplate implements HibernateOperations, InitializingBean /** * Return the names of Hibernate filters to be activated, if any. */ + @Nullable public String[] getFilterNames() { return this.filterNames; } @@ -322,6 +325,7 @@ public class HibernateTemplate implements HibernateOperations, InitializingBean * @return a result object returned by the action, or {@code null} * @throws DataAccessException in case of Hibernate errors */ + @Nullable public T executeWithNativeSession(HibernateCallback action) { return doExecute(action, true); } @@ -335,6 +339,7 @@ public class HibernateTemplate implements HibernateOperations, InitializingBean * @throws DataAccessException in case of Hibernate errors */ @SuppressWarnings("deprecation") + @Nullable protected T doExecute(HibernateCallback action, boolean enforceNativeSession) throws DataAccessException { Assert.notNull(action, "Callback object must not be null"); diff --git a/spring-orm/src/main/java/org/springframework/orm/hibernate5/HibernateTransactionManager.java b/spring-orm/src/main/java/org/springframework/orm/hibernate5/HibernateTransactionManager.java index 746d70c24d..325abb24df 100644 --- a/spring-orm/src/main/java/org/springframework/orm/hibernate5/HibernateTransactionManager.java +++ b/spring-orm/src/main/java/org/springframework/orm/hibernate5/HibernateTransactionManager.java @@ -18,6 +18,7 @@ package org.springframework.orm.hibernate5; import java.sql.Connection; import java.sql.ResultSet; + import javax.persistence.PersistenceException; import javax.sql.DataSource; @@ -41,6 +42,7 @@ import org.springframework.jdbc.datasource.ConnectionHolder; import org.springframework.jdbc.datasource.DataSourceUtils; import org.springframework.jdbc.datasource.JdbcTransactionObjectSupport; import org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy; +import org.springframework.lang.Nullable; import org.springframework.transaction.CannotCreateTransactionException; import org.springframework.transaction.IllegalTransactionStateException; import org.springframework.transaction.InvalidIsolationLevelException; @@ -313,6 +315,7 @@ public class HibernateTransactionManager extends AbstractPlatformTransactionMana * @see #setEntityInterceptorBeanName * @see #setBeanFactory */ + @Nullable public Interceptor getEntityInterceptor() throws IllegalStateException, BeansException { if (this.entityInterceptor instanceof Interceptor) { return (Interceptor) entityInterceptor; diff --git a/spring-orm/src/main/java/org/springframework/orm/hibernate5/LocalSessionFactoryBuilder.java b/spring-orm/src/main/java/org/springframework/orm/hibernate5/LocalSessionFactoryBuilder.java index 1736a575ce..b6058d1906 100644 --- a/spring-orm/src/main/java/org/springframework/orm/hibernate5/LocalSessionFactoryBuilder.java +++ b/spring-orm/src/main/java/org/springframework/orm/hibernate5/LocalSessionFactoryBuilder.java @@ -27,6 +27,7 @@ import java.util.TreeSet; import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; + import javax.persistence.AttributeConverter; import javax.persistence.Converter; import javax.persistence.Embeddable; @@ -58,6 +59,7 @@ import org.springframework.core.type.classreading.MetadataReader; import org.springframework.core.type.classreading.MetadataReaderFactory; import org.springframework.core.type.filter.AnnotationTypeFilter; import org.springframework.core.type.filter.TypeFilter; +import org.springframework.lang.Nullable; import org.springframework.transaction.jta.JtaTransactionManager; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; @@ -101,7 +103,7 @@ public class LocalSessionFactoryBuilder extends Configuration { * @param dataSource the JDBC DataSource that the resulting Hibernate SessionFactory should be using * (may be {@code null}) */ - public LocalSessionFactoryBuilder(DataSource dataSource) { + public LocalSessionFactoryBuilder(@Nullable DataSource dataSource) { this(dataSource, new PathMatchingResourcePatternResolver()); } @@ -111,7 +113,7 @@ public class LocalSessionFactoryBuilder extends Configuration { * (may be {@code null}) * @param classLoader the ClassLoader to load application classes from */ - public LocalSessionFactoryBuilder(DataSource dataSource, ClassLoader classLoader) { + public LocalSessionFactoryBuilder(@Nullable DataSource dataSource, ClassLoader classLoader) { this(dataSource, new PathMatchingResourcePatternResolver(classLoader)); } @@ -121,7 +123,7 @@ public class LocalSessionFactoryBuilder extends Configuration { * (may be {@code null}) * @param resourceLoader the ResourceLoader to load application classes from */ - public LocalSessionFactoryBuilder(DataSource dataSource, ResourceLoader resourceLoader) { + public LocalSessionFactoryBuilder(@Nullable DataSource dataSource, ResourceLoader resourceLoader) { this(dataSource, resourceLoader, new MetadataSources( new BootstrapServiceRegistryBuilder().applyClassLoader(resourceLoader.getClassLoader()).build())); } @@ -134,7 +136,7 @@ public class LocalSessionFactoryBuilder extends Configuration { * @param metadataSources the Hibernate MetadataSources service to use (e.g. reusing an existing one) * @since 4.3 */ - public LocalSessionFactoryBuilder(DataSource dataSource, ResourceLoader resourceLoader, MetadataSources metadataSources) { + public LocalSessionFactoryBuilder(@Nullable DataSource dataSource, ResourceLoader resourceLoader, MetadataSources metadataSources) { super(metadataSources); getProperties().put(AvailableSettings.CURRENT_SESSION_CONTEXT_CLASS, SpringSessionContext.class.getName()); diff --git a/spring-orm/src/main/java/org/springframework/orm/hibernate5/SessionFactoryUtils.java b/spring-orm/src/main/java/org/springframework/orm/hibernate5/SessionFactoryUtils.java index fafa3f6b78..be1c99f508 100644 --- a/spring-orm/src/main/java/org/springframework/orm/hibernate5/SessionFactoryUtils.java +++ b/spring-orm/src/main/java/org/springframework/orm/hibernate5/SessionFactoryUtils.java @@ -18,6 +18,7 @@ package org.springframework.orm.hibernate5; import java.lang.reflect.Method; import java.util.Map; + import javax.persistence.PersistenceException; import javax.sql.DataSource; @@ -63,6 +64,7 @@ import org.springframework.dao.InvalidDataAccessApiUsageException; import org.springframework.dao.InvalidDataAccessResourceUsageException; import org.springframework.dao.PessimisticLockingFailureException; import org.springframework.jdbc.datasource.DataSourceUtils; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.ReflectionUtils; @@ -161,7 +163,7 @@ public abstract class SessionFactoryUtils { * @param session the Hibernate Session to close (may be {@code null}) * @see Session#close() */ - public static void closeSession(Session session) { + public static void closeSession(@Nullable Session session) { if (session != null) { try { session.close(); @@ -181,6 +183,7 @@ public abstract class SessionFactoryUtils { * @return the DataSource, or {@code null} if none found * @see ConnectionProvider */ + @Nullable public static DataSource getDataSource(SessionFactory sessionFactory) { Method getProperties = ClassUtils.getMethodIfAvailable(sessionFactory.getClass(), "getProperties"); if (getProperties != null) { diff --git a/spring-orm/src/main/java/org/springframework/orm/hibernate5/package-info.java b/spring-orm/src/main/java/org/springframework/orm/hibernate5/package-info.java index 12f5d47003..1aa35f6d9c 100644 --- a/spring-orm/src/main/java/org/springframework/orm/hibernate5/package-info.java +++ b/spring-orm/src/main/java/org/springframework/orm/hibernate5/package-info.java @@ -10,4 +10,7 @@ * *

    This package supports Hibernate 5.x only. */ +@NonNullApi package org.springframework.orm.hibernate5; + +import org.springframework.lang.NonNullApi; diff --git a/spring-orm/src/main/java/org/springframework/orm/hibernate5/support/package-info.java b/spring-orm/src/main/java/org/springframework/orm/hibernate5/support/package-info.java index 7c7c5a9efc..1b458ddb7b 100644 --- a/spring-orm/src/main/java/org/springframework/orm/hibernate5/support/package-info.java +++ b/spring-orm/src/main/java/org/springframework/orm/hibernate5/support/package-info.java @@ -1,4 +1,7 @@ /** * Classes supporting the {@code org.springframework.orm.hibernate5} package. */ +@NonNullApi package org.springframework.orm.hibernate5.support; + +import org.springframework.lang.NonNullApi; diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/AbstractEntityManagerFactoryBean.java b/spring-orm/src/main/java/org/springframework/orm/jpa/AbstractEntityManagerFactoryBean.java index 4a898b3710..15b985a35a 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/AbstractEntityManagerFactoryBean.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/AbstractEntityManagerFactoryBean.java @@ -33,6 +33,7 @@ import java.util.Set; import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; + import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; import javax.persistence.PersistenceException; @@ -55,6 +56,7 @@ import org.springframework.beans.factory.InitializingBean; import org.springframework.core.task.AsyncTaskExecutor; import org.springframework.dao.DataAccessException; import org.springframework.dao.support.PersistenceExceptionTranslator; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.CollectionUtils; @@ -267,6 +269,7 @@ public abstract class AbstractEntityManagerFactoryBean implements * Return the JpaVendorAdapter implementation for this * EntityManagerFactory, or {@code null} if not known. */ + @Nullable public JpaVendorAdapter getJpaVendorAdapter() { return this.jpaVendorAdapter; } @@ -291,6 +294,7 @@ public abstract class AbstractEntityManagerFactoryBean implements * Return the asynchronous executor for background bootstrapping, if any. * @since 4.3 */ + @Nullable public AsyncTaskExecutor getBootstrapExecutor() { return this.bootstrapExecutor; } diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerFactoryAccessor.java b/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerFactoryAccessor.java index 5fd48d9563..5f71fe5acd 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerFactoryAccessor.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerFactoryAccessor.java @@ -19,6 +19,7 @@ package org.springframework.orm.jpa; import java.util.HashMap; import java.util.Map; import java.util.Properties; + import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; @@ -29,6 +30,7 @@ import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.beans.factory.ListableBeanFactory; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; @@ -85,6 +87,7 @@ public abstract class EntityManagerFactoryAccessor implements BeanFactoryAware { /** * Return the name of the persistence unit to access the EntityManagerFactory for, if any. */ + @Nullable public String getPersistenceUnitName() { return this.persistenceUnitName; } @@ -106,7 +109,7 @@ public abstract class EntityManagerFactoryAccessor implements BeanFactoryAware { *

    Can be populated with a "map" or "props" element in XML bean definitions. * @see javax.persistence.EntityManagerFactory#createEntityManager(java.util.Map) */ - public void setJpaPropertyMap(Map jpaProperties) { + public void setJpaPropertyMap(@Nullable Map jpaProperties) { if (jpaProperties != null) { this.jpaPropertyMap.putAll(jpaProperties); } @@ -161,6 +164,7 @@ public abstract class EntityManagerFactoryAccessor implements BeanFactoryAware { * @see EntityManagerFactoryUtils#getTransactionalEntityManager(javax.persistence.EntityManagerFactory) * @see EntityManagerFactoryUtils#getTransactionalEntityManager(javax.persistence.EntityManagerFactory, java.util.Map) */ + @Nullable protected EntityManager getTransactionalEntityManager() throws IllegalStateException{ EntityManagerFactory emf = getEntityManagerFactory(); Assert.state(emf != null, "No EntityManagerFactory specified"); diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerFactoryInfo.java b/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerFactoryInfo.java index bdb38dcd66..16114ac930 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerFactoryInfo.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerFactoryInfo.java @@ -22,6 +22,8 @@ import javax.persistence.spi.PersistenceProvider; import javax.persistence.spi.PersistenceUnitInfo; import javax.sql.DataSource; +import org.springframework.lang.Nullable; + /** * Metadata interface for a Spring-managed JPA {@link EntityManagerFactory}. * @@ -47,6 +49,7 @@ public interface EntityManagerFactoryInfo { * or {@code null} if the standard JPA provider autodetection process * was used to configure the EntityManagerFactory */ + @Nullable PersistenceProvider getPersistenceProvider(); /** @@ -56,6 +59,7 @@ public interface EntityManagerFactoryInfo { * or {@code null} if the in-container contract was not used to * configure the EntityManagerFactory */ + @Nullable PersistenceUnitInfo getPersistenceUnitInfo(); /** @@ -67,6 +71,7 @@ public interface EntityManagerFactoryInfo { * @see #getPersistenceUnitInfo() * @see javax.persistence.spi.PersistenceUnitInfo#getPersistenceUnitName() */ + @Nullable String getPersistenceUnitName(); /** @@ -74,6 +79,7 @@ public interface EntityManagerFactoryInfo { * obtains its JDBC Connections from. * @return the JDBC DataSource, or {@code null} if not known */ + @Nullable DataSource getDataSource(); /** @@ -83,12 +89,14 @@ public interface EntityManagerFactoryInfo { * to happen: either based on a target {@code EntityManager} instance * or simply defaulting to {@code javax.persistence.EntityManager}. */ + @Nullable Class getEntityManagerInterface(); /** * Return the vendor-specific JpaDialect implementation for this * EntityManagerFactory, or {@code null} if not known. */ + @Nullable JpaDialect getJpaDialect(); /** diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerFactoryUtils.java b/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerFactoryUtils.java index 43e98f3c42..12d4ccbc25 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerFactoryUtils.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerFactoryUtils.java @@ -17,6 +17,7 @@ package org.springframework.orm.jpa; import java.util.Map; + import javax.persistence.EntityExistsException; import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; @@ -48,6 +49,7 @@ import org.springframework.dao.IncorrectResultSizeDataAccessException; import org.springframework.dao.InvalidDataAccessApiUsageException; import org.springframework.dao.PessimisticLockingFailureException; import org.springframework.jdbc.datasource.DataSourceUtils; +import org.springframework.lang.Nullable; import org.springframework.transaction.support.ResourceHolderSynchronization; import org.springframework.transaction.support.TransactionSynchronizationManager; import org.springframework.util.Assert; @@ -96,7 +98,7 @@ public abstract class EntityManagerFactoryUtils { * @see EntityManagerFactoryInfo#getPersistenceUnitName() */ public static EntityManagerFactory findEntityManagerFactory( - ListableBeanFactory beanFactory, String unitName) throws NoSuchBeanDefinitionException { + ListableBeanFactory beanFactory, @Nullable String unitName) throws NoSuchBeanDefinitionException { Assert.notNull(beanFactory, "ListableBeanFactory must not be null"); if (StringUtils.hasLength(unitName)) { @@ -130,6 +132,7 @@ public abstract class EntityManagerFactoryUtils { * @throws DataAccessResourceFailureException if the EntityManager couldn't be obtained * @see JpaTransactionManager */ + @Nullable public static EntityManager getTransactionalEntityManager(EntityManagerFactory emf) throws DataAccessResourceFailureException { @@ -147,7 +150,8 @@ public abstract class EntityManagerFactoryUtils { * @throws DataAccessResourceFailureException if the EntityManager couldn't be obtained * @see JpaTransactionManager */ - public static EntityManager getTransactionalEntityManager(EntityManagerFactory emf, Map properties) + @Nullable + public static EntityManager getTransactionalEntityManager(EntityManagerFactory emf, @Nullable Map properties) throws DataAccessResourceFailureException { try { return doGetTransactionalEntityManager(emf, properties, true); @@ -169,6 +173,7 @@ public abstract class EntityManagerFactoryUtils { * @see #getTransactionalEntityManager(javax.persistence.EntityManagerFactory) * @see JpaTransactionManager */ + @Nullable public static EntityManager doGetTransactionalEntityManager(EntityManagerFactory emf, Map properties) throws PersistenceException { @@ -189,8 +194,9 @@ public abstract class EntityManagerFactoryUtils { * @see #getTransactionalEntityManager(javax.persistence.EntityManagerFactory) * @see JpaTransactionManager */ + @Nullable public static EntityManager doGetTransactionalEntityManager( - EntityManagerFactory emf, Map properties, boolean synchronizedWithTransaction) throws PersistenceException { + EntityManagerFactory emf, @Nullable Map properties, boolean synchronizedWithTransaction) throws PersistenceException { Assert.notNull(emf, "No EntityManagerFactory specified"); @@ -289,6 +295,7 @@ public abstract class EntityManagerFactoryUtils { * (to be passed into cleanupTransaction) * @see JpaDialect#prepareTransaction */ + @Nullable private static Object prepareTransaction(EntityManager em, EntityManagerFactory emf) { if (emf instanceof EntityManagerFactoryInfo) { EntityManagerFactoryInfo emfInfo = (EntityManagerFactoryInfo) emf; @@ -350,6 +357,7 @@ public abstract class EntityManagerFactoryUtils { * @return the corresponding DataAccessException instance, * or {@code null} if the exception should not be translated */ + @Nullable public static DataAccessException convertJpaAccessExceptionIfPossible(RuntimeException ex) { // Following the JPA specification, a persistence provider can also // throw these two exceptions, besides PersistenceException. @@ -406,7 +414,7 @@ public abstract class EntityManagerFactoryUtils { * @param em the JPA EntityManager to close (may be {@code null}) * @see javax.persistence.EntityManager#close() */ - public static void closeEntityManager(EntityManager em) { + public static void closeEntityManager(@Nullable EntityManager em) { if (em != null) { logger.debug("Closing JPA EntityManager"); try { diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/ExtendedEntityManagerCreator.java b/spring-orm/src/main/java/org/springframework/orm/jpa/ExtendedEntityManagerCreator.java index cc7bde2aee..af2f6eeb17 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/ExtendedEntityManagerCreator.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/ExtendedEntityManagerCreator.java @@ -24,6 +24,7 @@ import java.lang.reflect.Proxy; import java.util.LinkedHashSet; import java.util.Map; import java.util.Set; + import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; import javax.persistence.EntityTransaction; @@ -37,6 +38,7 @@ import org.apache.commons.logging.LogFactory; import org.springframework.core.Ordered; import org.springframework.dao.DataAccessException; import org.springframework.dao.support.PersistenceExceptionTranslator; +import org.springframework.lang.Nullable; import org.springframework.transaction.support.ResourceHolderSynchronization; import org.springframework.transaction.support.TransactionSynchronizationManager; import org.springframework.util.Assert; @@ -141,7 +143,7 @@ public abstract class ExtendedEntityManagerCreator { * in any managed transaction * @see javax.persistence.EntityManagerFactory#createEntityManager(java.util.Map) */ - public static EntityManager createContainerManagedEntityManager(EntityManagerFactory emf, Map properties) { + public static EntityManager createContainerManagedEntityManager(EntityManagerFactory emf, @Nullable Map properties) { return createContainerManagedEntityManager(emf, properties, true); } @@ -160,7 +162,7 @@ public abstract class ExtendedEntityManagerCreator { * @since 4.0 */ public static EntityManager createContainerManagedEntityManager( - EntityManagerFactory emf, Map properties, boolean synchronizedWithTransaction) { + EntityManagerFactory emf, @Nullable Map properties, boolean synchronizedWithTransaction) { Assert.notNull(emf, "EntityManagerFactory must not be null"); if (emf instanceof EntityManagerFactoryInfo) { @@ -216,8 +218,8 @@ public abstract class ExtendedEntityManagerCreator { * @return the EntityManager proxy */ private static EntityManager createProxy( - EntityManager rawEm, Class emIfc, ClassLoader cl, - PersistenceExceptionTranslator exceptionTranslator, Boolean jta, + EntityManager rawEm, @Nullable Class emIfc, @Nullable ClassLoader cl, + PersistenceExceptionTranslator exceptionTranslator, @Nullable Boolean jta, boolean containerManaged, boolean synchronizedWithTransaction) { Assert.notNull(rawEm, "EntityManager must not be null"); @@ -278,6 +280,7 @@ public abstract class ExtendedEntityManagerCreator { } @Override + @Nullable public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { // Invocation on EntityManager interface coming in... diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/JpaDialect.java b/spring-orm/src/main/java/org/springframework/orm/jpa/JpaDialect.java index e37b55aed9..f69ef56596 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/JpaDialect.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/JpaDialect.java @@ -17,11 +17,13 @@ package org.springframework.orm.jpa; import java.sql.SQLException; + import javax.persistence.EntityManager; import javax.persistence.PersistenceException; import org.springframework.dao.support.PersistenceExceptionTranslator; import org.springframework.jdbc.datasource.ConnectionHandle; +import org.springframework.lang.Nullable; import org.springframework.transaction.TransactionDefinition; import org.springframework.transaction.TransactionException; @@ -78,6 +80,7 @@ public interface JpaDialect extends PersistenceExceptionTranslator { * @see javax.persistence.EntityTransaction#begin * @see org.springframework.jdbc.datasource.DataSourceUtils#prepareConnectionForTransaction */ + @Nullable Object beginTransaction(EntityManager entityManager, TransactionDefinition definition) throws PersistenceException, SQLException, TransactionException; @@ -100,6 +103,7 @@ public interface JpaDialect extends PersistenceExceptionTranslator { * @throws javax.persistence.PersistenceException if thrown by JPA methods * @see #cleanupTransaction */ + @Nullable Object prepareTransaction(EntityManager entityManager, boolean readOnly, String name) throws PersistenceException; @@ -114,7 +118,7 @@ public interface JpaDialect extends PersistenceExceptionTranslator { * @see #beginTransaction * @see org.springframework.jdbc.datasource.DataSourceUtils#resetConnectionAfterTransaction */ - void cleanupTransaction(Object transactionData); + void cleanupTransaction(@Nullable Object transactionData); /** * Retrieve the JDBC Connection that the given JPA EntityManager uses underneath, @@ -146,6 +150,7 @@ public interface JpaDialect extends PersistenceExceptionTranslator { * @see org.springframework.jdbc.datasource.SimpleConnectionHandle * @see JpaTransactionManager#setDataSource */ + @Nullable ConnectionHandle getJdbcConnection(EntityManager entityManager, boolean readOnly) throws PersistenceException, SQLException; diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/JpaTransactionManager.java b/spring-orm/src/main/java/org/springframework/orm/jpa/JpaTransactionManager.java index 37febe21dc..ebd234f795 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/JpaTransactionManager.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/JpaTransactionManager.java @@ -37,6 +37,7 @@ import org.springframework.jdbc.datasource.ConnectionHandle; import org.springframework.jdbc.datasource.ConnectionHolder; import org.springframework.jdbc.datasource.JdbcTransactionObjectSupport; import org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy; +import org.springframework.lang.Nullable; import org.springframework.transaction.CannotCreateTransactionException; import org.springframework.transaction.IllegalTransactionStateException; import org.springframework.transaction.NestedTransactionNotSupportedException; @@ -175,6 +176,7 @@ public class JpaTransactionManager extends AbstractPlatformTransactionManager /** * Return the name of the persistence unit to manage transactions for, if any. */ + @Nullable public String getPersistenceUnitName() { return this.persistenceUnitName; } @@ -186,7 +188,7 @@ public class JpaTransactionManager extends AbstractPlatformTransactionManager * or a "props" element in XML bean definitions. * @see javax.persistence.EntityManagerFactory#createEntityManager(java.util.Map) */ - public void setJpaProperties(Properties jpaProperties) { + public void setJpaProperties(@Nullable Properties jpaProperties) { CollectionUtils.mergePropertiesIntoMap(jpaProperties, this.jpaPropertyMap); } @@ -196,7 +198,7 @@ public class JpaTransactionManager extends AbstractPlatformTransactionManager *

    Can be populated with a "map" or "props" element in XML bean definitions. * @see javax.persistence.EntityManagerFactory#createEntityManager(java.util.Map) */ - public void setJpaPropertyMap(Map jpaProperties) { + public void setJpaPropertyMap(@Nullable Map jpaProperties) { if (jpaProperties != null) { this.jpaPropertyMap.putAll(jpaProperties); } diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/JpaVendorAdapter.java b/spring-orm/src/main/java/org/springframework/orm/jpa/JpaVendorAdapter.java index 84923cf260..6809c90746 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/JpaVendorAdapter.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/JpaVendorAdapter.java @@ -17,10 +17,13 @@ package org.springframework.orm.jpa; import java.util.Map; + import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; import javax.persistence.spi.PersistenceProvider; +import org.springframework.lang.Nullable; + /** * SPI interface that allows to plug in vendor-specific behavior * into Spring's EntityManagerFactory creators. Serves as single @@ -44,6 +47,7 @@ public interface JpaVendorAdapter { * excluding provider classes from temporary class overriding. * @since 2.5.2 */ + @Nullable String getPersistenceProviderRootPackage(); /** @@ -58,12 +62,14 @@ public interface JpaVendorAdapter { * @see javax.persistence.Persistence#createEntityManagerFactory(String, java.util.Map) * @see javax.persistence.spi.PersistenceProvider#createContainerEntityManagerFactory(javax.persistence.spi.PersistenceUnitInfo, java.util.Map) */ + @Nullable Map getJpaPropertyMap(); /** * Return the vendor-specific JpaDialect implementation for this * provider, or {@code null} if there is none. */ + @Nullable JpaDialect getJpaDialect(); /** diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/SharedEntityManagerCreator.java b/spring-orm/src/main/java/org/springframework/orm/jpa/SharedEntityManagerCreator.java index 9582c8f795..1f52818259 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/SharedEntityManagerCreator.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/SharedEntityManagerCreator.java @@ -26,6 +26,7 @@ import java.lang.reflect.Proxy; import java.util.HashSet; import java.util.Map; import java.util.Set; + import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; import javax.persistence.Query; @@ -34,6 +35,7 @@ import javax.persistence.TransactionRequiredException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.lang.Nullable; import org.springframework.transaction.support.TransactionSynchronizationManager; import org.springframework.util.ClassUtils; import org.springframework.util.CollectionUtils; @@ -100,7 +102,7 @@ public abstract class SharedEntityManagerCreator { * {@code createEntityManager} call (may be {@code null}) * @return a shareable transaction EntityManager proxy */ - public static EntityManager createSharedEntityManager(EntityManagerFactory emf, Map properties) { + public static EntityManager createSharedEntityManager(EntityManagerFactory emf, @Nullable Map properties) { return createSharedEntityManager(emf, properties, true); } @@ -115,7 +117,7 @@ public abstract class SharedEntityManagerCreator { * @since 4.0 */ public static EntityManager createSharedEntityManager( - EntityManagerFactory emf, Map properties, boolean synchronizedWithTransaction) { + EntityManagerFactory emf, @Nullable Map properties, boolean synchronizedWithTransaction) { Class emIfc = (emf instanceof EntityManagerFactoryInfo ? ((EntityManagerFactoryInfo) emf).getEntityManagerInterface() : EntityManager.class); @@ -133,7 +135,7 @@ public abstract class SharedEntityManagerCreator { * @return a shareable transactional EntityManager proxy */ public static EntityManager createSharedEntityManager( - EntityManagerFactory emf, Map properties, Class... entityManagerInterfaces) { + EntityManagerFactory emf, @Nullable Map properties, Class... entityManagerInterfaces) { return createSharedEntityManager(emf, properties, true, entityManagerInterfaces); } @@ -150,7 +152,7 @@ public abstract class SharedEntityManagerCreator { * @return a shareable transactional EntityManager proxy * @since 4.0 */ - public static EntityManager createSharedEntityManager(EntityManagerFactory emf, Map properties, + public static EntityManager createSharedEntityManager(EntityManagerFactory emf, @Nullable Map properties, boolean synchronizedWithTransaction, Class... entityManagerInterfaces) { ClassLoader cl = null; @@ -202,6 +204,7 @@ public abstract class SharedEntityManagerCreator { } @Override + @Nullable public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { // Invocation on EntityManager interface coming in... diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/package-info.java b/spring-orm/src/main/java/org/springframework/orm/jpa/package-info.java index f7f42087e9..9d1058b4a5 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/package-info.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/package-info.java @@ -3,4 +3,7 @@ * Contains EntityManagerFactory helper classes, a template plus callback for JPA access, * and an implementation of Spring's transaction SPI for local JPA transactions. */ +@NonNullApi package org.springframework.orm.jpa; + +import org.springframework.lang.NonNullApi; diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/ClassFileTransformerAdapter.java b/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/ClassFileTransformerAdapter.java index 9db7454c43..370427379a 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/ClassFileTransformerAdapter.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/ClassFileTransformerAdapter.java @@ -23,6 +23,7 @@ import javax.persistence.spi.ClassTransformer; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -52,6 +53,7 @@ class ClassFileTransformerAdapter implements ClassFileTransformer { @Override + @Nullable public byte[] transform( ClassLoader loader, String className, Class classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) { diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/DefaultPersistenceUnitManager.java b/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/DefaultPersistenceUnitManager.java index bf9283eae2..77a8435d29 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/DefaultPersistenceUnitManager.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/DefaultPersistenceUnitManager.java @@ -25,6 +25,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; + import javax.persistence.Converter; import javax.persistence.Embeddable; import javax.persistence.Entity; @@ -58,6 +59,7 @@ import org.springframework.instrument.classloading.LoadTimeWeaver; import org.springframework.jdbc.datasource.lookup.DataSourceLookup; import org.springframework.jdbc.datasource.lookup.JndiDataSourceLookup; import org.springframework.jdbc.datasource.lookup.MapDataSourceLookup; +import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.util.ObjectUtils; import org.springframework.util.ResourceUtils; @@ -610,6 +612,7 @@ public class DefaultPersistenceUnitManager * @return the persistence unit root URL to pass to the JPA PersistenceProvider * @see #setDefaultPersistenceUnitRootLocation */ + @Nullable private URL determineDefaultPersistenceUnitRootUrl() { if (this.defaultPersistenceUnitRootLocation == null) { return null; @@ -629,6 +632,7 @@ public class DefaultPersistenceUnitManager *

    Checks whether a "META-INF/orm.xml" file exists in the classpath and uses it * if it is not co-located with a "META-INF/persistence.xml" file. */ + @Nullable private Resource getOrmXmlForDefaultPersistenceUnit() { Resource ormXml = this.resourcePatternResolver.getResource( this.defaultPersistenceUnitRootLocation + DEFAULT_ORM_XML_RESOURCE); @@ -657,6 +661,7 @@ public class DefaultPersistenceUnitManager * @param persistenceUnitName the name of the desired persistence unit * @return the PersistenceUnitInfo in mutable form, or {@code null} if not available */ + @Nullable protected final MutablePersistenceUnitInfo getPersistenceUnitInfo(String persistenceUnitName) { PersistenceUnitInfo pui = this.persistenceUnitInfos.get(persistenceUnitName); return (MutablePersistenceUnitInfo) pui; diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/PersistenceUnitReader.java b/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/PersistenceUnitReader.java index 30b038fef6..e947803d6b 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/PersistenceUnitReader.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/PersistenceUnitReader.java @@ -38,6 +38,7 @@ import org.xml.sax.SAXException; import org.springframework.core.io.Resource; import org.springframework.core.io.support.ResourcePatternResolver; import org.springframework.jdbc.datasource.lookup.DataSourceLookup; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ResourceUtils; import org.springframework.util.StringUtils; @@ -332,6 +333,7 @@ final class PersistenceUnitReader { * @return the corresponding persistence unit root URL * @throws IOException if the checking failed */ + @Nullable static URL determinePersistenceUnitRootUrl(Resource resource) throws IOException { URL originalURL = resource.getURL(); diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/package-info.java b/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/package-info.java index aab558ab60..3f6597093f 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/package-info.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/package-info.java @@ -1,4 +1,7 @@ /** * Internal support for managing JPA persistence units. */ +@NonNullApi package org.springframework.orm.jpa.persistenceunit; + +import org.springframework.lang.NonNullApi; diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/support/OpenEntityManagerInViewFilter.java b/spring-orm/src/main/java/org/springframework/orm/jpa/support/OpenEntityManagerInViewFilter.java index c69d69b4af..1ac2421fdc 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/support/OpenEntityManagerInViewFilter.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/support/OpenEntityManagerInViewFilter.java @@ -26,6 +26,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.dao.DataAccessResourceFailureException; +import org.springframework.lang.Nullable; import org.springframework.orm.jpa.EntityManagerFactoryUtils; import org.springframework.orm.jpa.EntityManagerHolder; import org.springframework.transaction.support.TransactionSynchronizationManager; @@ -116,6 +117,7 @@ public class OpenEntityManagerInViewFilter extends OncePerRequestFilter { /** * Return the name of the persistence unit to access the EntityManagerFactory for, if any. */ + @Nullable protected String getPersistenceUnitName() { return this.persistenceUnitName; } diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/support/PersistenceAnnotationBeanPostProcessor.java b/spring-orm/src/main/java/org/springframework/orm/jpa/support/PersistenceAnnotationBeanPostProcessor.java index 93ff738fde..05d9eb53b2 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/support/PersistenceAnnotationBeanPostProcessor.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/support/PersistenceAnnotationBeanPostProcessor.java @@ -27,6 +27,7 @@ import java.util.LinkedList; import java.util.Map; import java.util.Properties; import java.util.concurrent.ConcurrentHashMap; + import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; import javax.persistence.PersistenceContext; @@ -56,6 +57,7 @@ import org.springframework.core.Ordered; import org.springframework.core.PriorityOrdered; import org.springframework.jndi.JndiLocatorDelegate; import org.springframework.jndi.JndiTemplate; +import org.springframework.lang.Nullable; import org.springframework.orm.jpa.EntityManagerFactoryInfo; import org.springframework.orm.jpa.EntityManagerFactoryUtils; import org.springframework.orm.jpa.EntityManagerProxy; @@ -302,7 +304,7 @@ public class PersistenceAnnotationBeanPostProcessor * such factories, either specify this default persistence unit name * or explicitly refer to named persistence units in your annotations. */ - public void setDefaultPersistenceUnitName(String unitName) { + public void setDefaultPersistenceUnitName(@Nullable String unitName) { this.defaultPersistenceUnitName = (unitName != null ? unitName : ""); } @@ -456,6 +458,7 @@ public class PersistenceAnnotationBeanPostProcessor * or {@code null} if none found * @see #setPersistenceUnits */ + @Nullable protected EntityManagerFactory getPersistenceUnit(String unitName) { if (this.persistenceUnits != null) { String unitNameForLookup = (unitName != null ? unitName : ""); @@ -487,6 +490,7 @@ public class PersistenceAnnotationBeanPostProcessor * @see #setPersistenceContexts * @see #setExtendedPersistenceContexts */ + @Nullable protected EntityManager getPersistenceContext(String unitName, boolean extended) { Map contexts = (extended ? this.extendedPersistenceContexts : this.persistenceContexts); if (contexts != null) { @@ -519,7 +523,7 @@ public class PersistenceAnnotationBeanPostProcessor * @return the EntityManagerFactory * @throws NoSuchBeanDefinitionException if there is no such EntityManagerFactory in the context */ - protected EntityManagerFactory findEntityManagerFactory(String unitName, String requestingBeanName) + protected EntityManagerFactory findEntityManagerFactory(@Nullable String unitName, String requestingBeanName) throws NoSuchBeanDefinitionException { if (this.beanFactory == null) { diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/support/package-info.java b/spring-orm/src/main/java/org/springframework/orm/jpa/support/package-info.java index 4b36a106bb..81c5526ba3 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/support/package-info.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/support/package-info.java @@ -1,4 +1,7 @@ /** * Classes supporting the {@code org.springframework.orm.jpa} package. */ +@NonNullApi package org.springframework.orm.jpa.support; + +import org.springframework.lang.NonNullApi; diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/EclipseLinkJpaVendorAdapter.java b/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/EclipseLinkJpaVendorAdapter.java index d845df0ccc..f8d437740e 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/EclipseLinkJpaVendorAdapter.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/EclipseLinkJpaVendorAdapter.java @@ -19,6 +19,7 @@ package org.springframework.orm.jpa.vendor; import java.util.HashMap; import java.util.Map; import java.util.logging.Level; + import javax.persistence.EntityManager; import javax.persistence.spi.PersistenceProvider; @@ -26,6 +27,8 @@ import org.eclipse.persistence.config.PersistenceUnitProperties; import org.eclipse.persistence.config.TargetDatabase; import org.eclipse.persistence.jpa.JpaEntityManager; +import org.springframework.lang.Nullable; + /** * {@link org.springframework.orm.jpa.JpaVendorAdapter} implementation for Eclipse * Persistence Services (EclipseLink). Developed and tested against EclipseLink 2.4. @@ -88,6 +91,7 @@ public class EclipseLinkJpaVendorAdapter extends AbstractJpaVendorAdapter { * @param database the specified database * @return the EclipseLink target database name, or {@code null} if none found */ + @Nullable protected String determineTargetDatabaseName(Database database) { switch (database) { case DB2: return TargetDatabase.DB2; diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/HibernateJpaDialect.java b/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/HibernateJpaDialect.java index 93458e7bdd..5e2db94140 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/HibernateJpaDialect.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/HibernateJpaDialect.java @@ -58,6 +58,7 @@ import org.springframework.dao.InvalidDataAccessResourceUsageException; import org.springframework.dao.PessimisticLockingFailureException; import org.springframework.jdbc.datasource.ConnectionHandle; import org.springframework.jdbc.datasource.DataSourceUtils; +import org.springframework.lang.Nullable; import org.springframework.orm.ObjectOptimisticLockingFailureException; import org.springframework.orm.ObjectRetrievalFailureException; import org.springframework.orm.jpa.DefaultJpaDialect; @@ -177,6 +178,7 @@ public class HibernateJpaDialect extends DefaultJpaDialect { } @SuppressWarnings("deprecation") + @Nullable protected FlushMode prepareFlushMode(Session session, boolean readOnly) throws PersistenceException { FlushMode flushMode = (FlushMode) ReflectionUtils.invokeMethod(getFlushMode, session); if (readOnly) { diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/HibernateJpaVendorAdapter.java b/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/HibernateJpaVendorAdapter.java index 302dfd4a53..5a919c70fb 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/HibernateJpaVendorAdapter.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/HibernateJpaVendorAdapter.java @@ -18,6 +18,7 @@ package org.springframework.orm.jpa.vendor; import java.util.HashMap; import java.util.Map; + import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; import javax.persistence.spi.PersistenceProvider; @@ -34,6 +35,8 @@ import org.hibernate.dialect.PostgreSQL95Dialect; import org.hibernate.dialect.SQLServer2012Dialect; import org.hibernate.dialect.SybaseDialect; +import org.springframework.lang.Nullable; + /** * {@link org.springframework.orm.jpa.JpaVendorAdapter} implementation for Hibernate * EntityManager. Developed and tested against Hibernate 5.0, 5.1 and 5.2; @@ -155,6 +158,7 @@ public class HibernateJpaVendorAdapter extends AbstractJpaVendorAdapter { * @param database the target database * @return the Hibernate database dialect class, or {@code null} if none found */ + @Nullable protected Class determineDatabaseDialectClass(Database database) { switch (database) { case DB2: return DB2Dialect.class; diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/package-info.java b/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/package-info.java index 2ae2863417..9a73ca9738 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/package-info.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/package-info.java @@ -1,4 +1,7 @@ /** * Support classes for adapting to specific JPA vendors. */ +@NonNullApi package org.springframework.orm.jpa.vendor; + +import org.springframework.lang.NonNullApi; diff --git a/spring-orm/src/main/java/org/springframework/orm/package-info.java b/spring-orm/src/main/java/org/springframework/orm/package-info.java index 7583db4a5a..54db68c895 100644 --- a/spring-orm/src/main/java/org/springframework/orm/package-info.java +++ b/spring-orm/src/main/java/org/springframework/orm/package-info.java @@ -2,4 +2,7 @@ * Root package for Spring's O/R Mapping integration classes. * Contains generic DataAccessExceptions related to O/R Mapping. */ +@NonNullApi package org.springframework.orm; + +import org.springframework.lang.NonNullApi; diff --git a/spring-oxm/src/main/java/org/springframework/oxm/castor/package-info.java b/spring-oxm/src/main/java/org/springframework/oxm/castor/package-info.java index 3c01940292..e923e079bb 100644 --- a/spring-oxm/src/main/java/org/springframework/oxm/castor/package-info.java +++ b/spring-oxm/src/main/java/org/springframework/oxm/castor/package-info.java @@ -2,4 +2,7 @@ * Package providing integration of Castor * within Spring's O/X Mapping support. */ +@NonNullApi package org.springframework.oxm.castor; + +import org.springframework.lang.NonNullApi; diff --git a/spring-oxm/src/main/java/org/springframework/oxm/config/package-info.java b/spring-oxm/src/main/java/org/springframework/oxm/config/package-info.java index ed05ef9c6f..b91bda602b 100644 --- a/spring-oxm/src/main/java/org/springframework/oxm/config/package-info.java +++ b/spring-oxm/src/main/java/org/springframework/oxm/config/package-info.java @@ -1,4 +1,7 @@ /** * Provides an namespace handler for the Spring Object/XML namespace. */ +@NonNullApi package org.springframework.oxm.config; + +import org.springframework.lang.NonNullApi; diff --git a/spring-oxm/src/main/java/org/springframework/oxm/jaxb/package-info.java b/spring-oxm/src/main/java/org/springframework/oxm/jaxb/package-info.java index 8d0d6c2457..67aa0c8174 100644 --- a/spring-oxm/src/main/java/org/springframework/oxm/jaxb/package-info.java +++ b/spring-oxm/src/main/java/org/springframework/oxm/jaxb/package-info.java @@ -2,4 +2,7 @@ * Package providing integration of JAXB * with Spring's O/X Mapping support. */ +@NonNullApi package org.springframework.oxm.jaxb; + +import org.springframework.lang.NonNullApi; diff --git a/spring-oxm/src/main/java/org/springframework/oxm/jibx/package-info.java b/spring-oxm/src/main/java/org/springframework/oxm/jibx/package-info.java index 5d669ca5ee..2e4f620570 100644 --- a/spring-oxm/src/main/java/org/springframework/oxm/jibx/package-info.java +++ b/spring-oxm/src/main/java/org/springframework/oxm/jibx/package-info.java @@ -2,4 +2,7 @@ * Package providing integration of JiBX * with Spring's O/X Mapping support. */ +@NonNullApi package org.springframework.oxm.jibx; + +import org.springframework.lang.NonNullApi; diff --git a/spring-oxm/src/main/java/org/springframework/oxm/mime/MimeContainer.java b/spring-oxm/src/main/java/org/springframework/oxm/mime/MimeContainer.java index f7535781b3..003f436274 100644 --- a/spring-oxm/src/main/java/org/springframework/oxm/mime/MimeContainer.java +++ b/spring-oxm/src/main/java/org/springframework/oxm/mime/MimeContainer.java @@ -18,6 +18,8 @@ package org.springframework.oxm.mime; import javax.activation.DataHandler; +import org.springframework.lang.Nullable; + /** * Represents a container for MIME attachments * Concrete implementations might adapt a SOAPMessage or an email message. @@ -56,6 +58,7 @@ public interface MimeContainer { * @param contentId the content id * @return the attachment, as a data handler */ + @Nullable DataHandler getAttachment(String contentId); } diff --git a/spring-oxm/src/main/java/org/springframework/oxm/mime/package-info.java b/spring-oxm/src/main/java/org/springframework/oxm/mime/package-info.java index 8a431da7bd..edffe67286 100644 --- a/spring-oxm/src/main/java/org/springframework/oxm/mime/package-info.java +++ b/spring-oxm/src/main/java/org/springframework/oxm/mime/package-info.java @@ -1,4 +1,7 @@ /** * Contains (un)marshallers optimized to store binary data in MIME attachments. */ +@NonNullApi package org.springframework.oxm.mime; + +import org.springframework.lang.NonNullApi; diff --git a/spring-oxm/src/main/java/org/springframework/oxm/package-info.java b/spring-oxm/src/main/java/org/springframework/oxm/package-info.java index 4f26b7be8b..d85077c13f 100644 --- a/spring-oxm/src/main/java/org/springframework/oxm/package-info.java +++ b/spring-oxm/src/main/java/org/springframework/oxm/package-info.java @@ -3,4 +3,7 @@ * Contains generic Marshaller and Unmarshaller interfaces, * and XmlMappingExceptions related to O/X Mapping */ +@NonNullApi package org.springframework.oxm; + +import org.springframework.lang.NonNullApi; diff --git a/spring-oxm/src/main/java/org/springframework/oxm/support/AbstractMarshaller.java b/spring-oxm/src/main/java/org/springframework/oxm/support/AbstractMarshaller.java index 6a396708c8..918a58d772 100644 --- a/spring-oxm/src/main/java/org/springframework/oxm/support/AbstractMarshaller.java +++ b/spring-oxm/src/main/java/org/springframework/oxm/support/AbstractMarshaller.java @@ -22,6 +22,7 @@ import java.io.OutputStream; import java.io.Reader; import java.io.StringReader; import java.io.Writer; + import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; @@ -50,6 +51,7 @@ import org.xml.sax.SAXException; import org.xml.sax.XMLReader; import org.xml.sax.ext.LexicalHandler; +import org.springframework.lang.Nullable; import org.springframework.oxm.Marshaller; import org.springframework.oxm.Unmarshaller; import org.springframework.oxm.UnmarshallingFailureException; @@ -199,6 +201,7 @@ public abstract class AbstractMarshaller implements Marshaller, Unmarshaller { * a byte stream, or {@code null} if none. *

    The default implementation returns {@code null}. */ + @Nullable protected String getDefaultEncoding() { return null; } @@ -519,7 +522,7 @@ public abstract class AbstractMarshaller implements Marshaller, Unmarshaller { * @throws XmlMappingException if the given object cannot be marshalled to the handlers */ protected abstract void marshalSaxHandlers( - Object graph, ContentHandler contentHandler, LexicalHandler lexicalHandler) + Object graph, ContentHandler contentHandler, @Nullable LexicalHandler lexicalHandler) throws XmlMappingException; /** diff --git a/spring-oxm/src/main/java/org/springframework/oxm/support/SaxResourceUtils.java b/spring-oxm/src/main/java/org/springframework/oxm/support/SaxResourceUtils.java index 881a3ca20b..bced1a45cc 100644 --- a/spring-oxm/src/main/java/org/springframework/oxm/support/SaxResourceUtils.java +++ b/spring-oxm/src/main/java/org/springframework/oxm/support/SaxResourceUtils.java @@ -21,6 +21,7 @@ import java.io.IOException; import org.xml.sax.InputSource; import org.springframework.core.io.Resource; +import org.springframework.lang.Nullable; /** * Convenient utility methods for dealing with SAX. @@ -50,6 +51,7 @@ public abstract class SaxResourceUtils { * Retrieve the URL from the given resource as System ID. *

    Returns {@code null} if it cannot be opened. */ + @Nullable private static String getSystemId(Resource resource) { try { return resource.getURI().toString(); diff --git a/spring-oxm/src/main/java/org/springframework/oxm/support/package-info.java b/spring-oxm/src/main/java/org/springframework/oxm/support/package-info.java index 248820f37e..d9f01a48c5 100644 --- a/spring-oxm/src/main/java/org/springframework/oxm/support/package-info.java +++ b/spring-oxm/src/main/java/org/springframework/oxm/support/package-info.java @@ -4,4 +4,7 @@ * with TrAX, MarshallingView for use withing Spring Web MVC, and the * MarshallingMessageConverter for use within Spring's JMS support. */ +@NonNullApi package org.springframework.oxm.support; + +import org.springframework.lang.NonNullApi; diff --git a/spring-oxm/src/main/java/org/springframework/oxm/xstream/package-info.java b/spring-oxm/src/main/java/org/springframework/oxm/xstream/package-info.java index 5a4ab71cf5..490e696cfe 100644 --- a/spring-oxm/src/main/java/org/springframework/oxm/xstream/package-info.java +++ b/spring-oxm/src/main/java/org/springframework/oxm/xstream/package-info.java @@ -2,4 +2,7 @@ * Package providing integration of XStream * with Spring's O/X Mapping support. */ +@NonNullApi package org.springframework.oxm.xstream; + +import org.springframework.lang.NonNullApi; diff --git a/spring-test/src/main/java/org/springframework/mock/env/package-info.java b/spring-test/src/main/java/org/springframework/mock/env/package-info.java index 1772b5c90e..b91f00c11b 100644 --- a/spring-test/src/main/java/org/springframework/mock/env/package-info.java +++ b/spring-test/src/main/java/org/springframework/mock/env/package-info.java @@ -7,4 +7,7 @@ *

    These mocks are useful for developing out-of-container * unit tests for code that depends on environment-specific properties. */ +@NonNullApi package org.springframework.mock.env; + +import org.springframework.lang.NonNullApi; diff --git a/spring-test/src/main/java/org/springframework/mock/http/client/package-info.java b/spring-test/src/main/java/org/springframework/mock/http/client/package-info.java index 1d2a2c0c83..f0b355ea37 100644 --- a/spring-test/src/main/java/org/springframework/mock/http/client/package-info.java +++ b/spring-test/src/main/java/org/springframework/mock/http/client/package-info.java @@ -3,4 +3,7 @@ * This package contains {@code MockClientHttpRequest} and * {@code MockClientHttpResponse}. */ +@NonNullApi package org.springframework.mock.http.client; + +import org.springframework.lang.NonNullApi; diff --git a/spring-test/src/main/java/org/springframework/mock/http/client/reactive/package-info.java b/spring-test/src/main/java/org/springframework/mock/http/client/reactive/package-info.java index 09ce8aec5c..04b01c2be0 100644 --- a/spring-test/src/main/java/org/springframework/mock/http/client/reactive/package-info.java +++ b/spring-test/src/main/java/org/springframework/mock/http/client/reactive/package-info.java @@ -1,4 +1,7 @@ /** * Mock implementations of reactive HTTP client contracts. */ +@NonNullApi package org.springframework.mock.http.client.reactive; + +import org.springframework.lang.NonNullApi; diff --git a/spring-test/src/main/java/org/springframework/mock/http/package-info.java b/spring-test/src/main/java/org/springframework/mock/http/package-info.java index aa81f7f8dc..62341effdb 100644 --- a/spring-test/src/main/java/org/springframework/mock/http/package-info.java +++ b/spring-test/src/main/java/org/springframework/mock/http/package-info.java @@ -3,4 +3,7 @@ * This package contains {@code MockHttpInputMessage} and * {@code MockHttpOutputMessage}. */ +@NonNullApi package org.springframework.mock.http; + +import org.springframework.lang.NonNullApi; diff --git a/spring-test/src/main/java/org/springframework/mock/http/server/reactive/package-info.java b/spring-test/src/main/java/org/springframework/mock/http/server/reactive/package-info.java index 5336e97ced..3b93b279e4 100644 --- a/spring-test/src/main/java/org/springframework/mock/http/server/reactive/package-info.java +++ b/spring-test/src/main/java/org/springframework/mock/http/server/reactive/package-info.java @@ -1,4 +1,7 @@ /** * Mock implementations of reactive HTTP server contracts. */ +@NonNullApi package org.springframework.mock.http.server.reactive; + +import org.springframework.lang.NonNullApi; diff --git a/spring-test/src/main/java/org/springframework/mock/jndi/SimpleNamingContextBuilder.java b/spring-test/src/main/java/org/springframework/mock/jndi/SimpleNamingContextBuilder.java index 9c96648cd3..58027c99e0 100644 --- a/spring-test/src/main/java/org/springframework/mock/jndi/SimpleNamingContextBuilder.java +++ b/spring-test/src/main/java/org/springframework/mock/jndi/SimpleNamingContextBuilder.java @@ -17,6 +17,7 @@ package org.springframework.mock.jndi; import java.util.Hashtable; + import javax.naming.Context; import javax.naming.NamingException; import javax.naming.spi.InitialContextFactory; @@ -26,6 +27,7 @@ import javax.naming.spi.NamingManager; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.ReflectionUtils; @@ -95,6 +97,7 @@ public class SimpleNamingContextBuilder implements InitialContextFactoryBuilder * @return the current SimpleNamingContextBuilder instance, * or {@code null} if none */ + @Nullable public static SimpleNamingContextBuilder getCurrentContextBuilder() { return activated; } diff --git a/spring-test/src/main/java/org/springframework/mock/jndi/package-info.java b/spring-test/src/main/java/org/springframework/mock/jndi/package-info.java index 13871e6e04..5aab8baf96 100644 --- a/spring-test/src/main/java/org/springframework/mock/jndi/package-info.java +++ b/spring-test/src/main/java/org/springframework/mock/jndi/package-info.java @@ -6,4 +6,7 @@ * same JNDI names as within a Java EE container, both application code and * configuration can be reused without changes. */ +@NonNullApi package org.springframework.mock.jndi; + +import org.springframework.lang.NonNullApi; diff --git a/spring-test/src/main/java/org/springframework/mock/web/HeaderValueHolder.java b/spring-test/src/main/java/org/springframework/mock/web/HeaderValueHolder.java index 9ef95c60b0..8cbd8a3cc5 100644 --- a/spring-test/src/main/java/org/springframework/mock/web/HeaderValueHolder.java +++ b/spring-test/src/main/java/org/springframework/mock/web/HeaderValueHolder.java @@ -23,6 +23,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; @@ -88,6 +89,7 @@ class HeaderValueHolder { * @return the corresponding HeaderValueHolder, * or {@code null} if none found */ + @Nullable public static HeaderValueHolder getByName(Map headers, String name) { Assert.notNull(name, "Header name must not be null"); for (String headerName : headers.keySet()) { diff --git a/spring-test/src/main/java/org/springframework/mock/web/MockHttpServletRequest.java b/spring-test/src/main/java/org/springframework/mock/web/MockHttpServletRequest.java index 5997ddd730..3dcca7305f 100644 --- a/spring-test/src/main/java/org/springframework/mock/web/MockHttpServletRequest.java +++ b/spring-test/src/main/java/org/springframework/mock/web/MockHttpServletRequest.java @@ -41,6 +41,7 @@ import java.util.Locale; import java.util.Map; import java.util.Set; import java.util.TimeZone; + import javax.servlet.AsyncContext; import javax.servlet.DispatcherType; import javax.servlet.RequestDispatcher; @@ -58,6 +59,7 @@ import javax.servlet.http.Part; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.LinkedCaseInsensitiveMap; import org.springframework.util.LinkedMultiValueMap; @@ -272,7 +274,7 @@ public class MockHttpServletRequest implements HttpServletRequest { * @see #setRequestURI * @see #MockHttpServletRequest(ServletContext, String, String) */ - public MockHttpServletRequest(String method, String requestURI) { + public MockHttpServletRequest(@Nullable String method, @Nullable String requestURI) { this(null, method, requestURI); } @@ -282,7 +284,7 @@ public class MockHttpServletRequest implements HttpServletRequest { * (may be {@code null} to use a default {@link MockServletContext}) * @see #MockHttpServletRequest(ServletContext, String, String) */ - public MockHttpServletRequest(ServletContext servletContext) { + public MockHttpServletRequest(@Nullable ServletContext servletContext) { this(servletContext, "", ""); } @@ -299,7 +301,7 @@ public class MockHttpServletRequest implements HttpServletRequest { * @see #setPreferredLocales * @see MockServletContext */ - public MockHttpServletRequest(ServletContext servletContext, String method, String requestURI) { + public MockHttpServletRequest(@Nullable ServletContext servletContext, @Nullable String method, @Nullable String requestURI) { this.servletContext = (servletContext != null ? servletContext : new MockServletContext()); this.method = method; this.requestURI = requestURI; @@ -409,6 +411,7 @@ public class MockHttpServletRequest implements HttpServletRequest { * @see #setContent(byte[]) * @see #getContentAsString() */ + @Nullable public byte[] getContentAsByteArray() { return this.content; } @@ -424,6 +427,7 @@ public class MockHttpServletRequest implements HttpServletRequest { * @see #setCharacterEncoding(String) * @see #getContentAsByteArray() */ + @Nullable public String getContentAsString() throws IllegalStateException, UnsupportedEncodingException { Assert.state(this.characterEncoding != null, "Cannot get content as a String for a null character encoding. " + diff --git a/spring-test/src/main/java/org/springframework/mock/web/MockHttpServletResponse.java b/spring-test/src/main/java/org/springframework/mock/web/MockHttpServletResponse.java index 28a5da0d12..2a85175e59 100644 --- a/spring-test/src/main/java/org/springframework/mock/web/MockHttpServletResponse.java +++ b/spring-test/src/main/java/org/springframework/mock/web/MockHttpServletResponse.java @@ -33,12 +33,14 @@ import java.util.List; import java.util.Locale; import java.util.Map; import java.util.TimeZone; + import javax.servlet.ServletOutputStream; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletResponse; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.LinkedCaseInsensitiveMap; import org.springframework.util.StringUtils; @@ -390,6 +392,7 @@ public class MockHttpServletResponse implements HttpServletResponse { * @return the associated header value, or {@code null} if none */ @Override + @Nullable public String getHeader(String name) { HeaderValueHolder header = HeaderValueHolder.getByName(this.headers, name); return (header != null ? header.getStringValue() : null); @@ -420,6 +423,7 @@ public class MockHttpServletResponse implements HttpServletResponse { * @param name the name of the header * @return the associated header value, or {@code null} if none */ + @Nullable public Object getHeaderValue(String name) { HeaderValueHolder header = HeaderValueHolder.getByName(this.headers, name); return (header != null ? header.getValue() : null); diff --git a/spring-test/src/main/java/org/springframework/mock/web/MockMultipartHttpServletRequest.java b/spring-test/src/main/java/org/springframework/mock/web/MockMultipartHttpServletRequest.java index bb47c6112d..49f9c1246c 100644 --- a/spring-test/src/main/java/org/springframework/mock/web/MockMultipartHttpServletRequest.java +++ b/spring-test/src/main/java/org/springframework/mock/web/MockMultipartHttpServletRequest.java @@ -21,10 +21,12 @@ import java.util.Enumeration; import java.util.Iterator; import java.util.List; import java.util.Map; + import javax.servlet.ServletContext; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; @@ -65,7 +67,7 @@ public class MockMultipartHttpServletRequest extends MockHttpServletRequest impl * @param servletContext the ServletContext that the request runs in * (may be {@code null} to use a default {@link MockServletContext}) */ - public MockMultipartHttpServletRequest(ServletContext servletContext) { + public MockMultipartHttpServletRequest(@Nullable ServletContext servletContext) { super(servletContext); setMethod("POST"); setContentType("multipart/form-data"); diff --git a/spring-test/src/main/java/org/springframework/mock/web/MockServletContext.java b/spring-test/src/main/java/org/springframework/mock/web/MockServletContext.java index ecab0ecf3c..1857c5144a 100644 --- a/spring-test/src/main/java/org/springframework/mock/web/MockServletContext.java +++ b/spring-test/src/main/java/org/springframework/mock/web/MockServletContext.java @@ -29,6 +29,7 @@ import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.Map; import java.util.Set; + import javax.servlet.Filter; import javax.servlet.FilterRegistration; import javax.servlet.RequestDispatcher; @@ -48,6 +49,7 @@ import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceLoader; import org.springframework.http.MediaType; import org.springframework.http.MediaTypeFactory; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.MimeType; @@ -165,7 +167,7 @@ public class MockServletContext implements ServletContext { * and no base path. * @param resourceLoader the ResourceLoader to use (or null for the default) */ - public MockServletContext(ResourceLoader resourceLoader) { + public MockServletContext(@Nullable ResourceLoader resourceLoader) { this("", resourceLoader); } @@ -178,7 +180,7 @@ public class MockServletContext implements ServletContext { * @param resourceLoader the ResourceLoader to use (or null for the default) * @see #registerNamedDispatcher */ - public MockServletContext(String resourceBasePath, ResourceLoader resourceLoader) { + public MockServletContext(String resourceBasePath, @Nullable ResourceLoader resourceLoader) { this.resourceLoader = (resourceLoader != null ? resourceLoader : new DefaultResourceLoader()); this.resourceBasePath = (resourceBasePath != null ? resourceBasePath : ""); @@ -630,6 +632,7 @@ public class MockServletContext implements ServletContext { * @see javax.servlet.ServletContext#getServletRegistration(java.lang.String) */ @Override + @Nullable public ServletRegistration getServletRegistration(String servletName) { return null; } @@ -668,6 +671,7 @@ public class MockServletContext implements ServletContext { * @see javax.servlet.ServletContext#getFilterRegistration(java.lang.String) */ @Override + @Nullable public FilterRegistration getFilterRegistration(String filterName) { return null; } diff --git a/spring-test/src/main/java/org/springframework/mock/web/package-info.java b/spring-test/src/main/java/org/springframework/mock/web/package-info.java index 720f52f5af..74414ef058 100644 --- a/spring-test/src/main/java/org/springframework/mock/web/package-info.java +++ b/spring-test/src/main/java/org/springframework/mock/web/package-info.java @@ -9,4 +9,7 @@ * existing Servlet API mock objects * (MockObjects). */ +@NonNullApi package org.springframework.mock.web; + +import org.springframework.lang.NonNullApi; diff --git a/spring-test/src/main/java/org/springframework/test/annotation/ProfileValueSource.java b/spring-test/src/main/java/org/springframework/test/annotation/ProfileValueSource.java index 05ee407f5f..e7427077b9 100644 --- a/spring-test/src/main/java/org/springframework/test/annotation/ProfileValueSource.java +++ b/spring-test/src/main/java/org/springframework/test/annotation/ProfileValueSource.java @@ -16,6 +16,8 @@ package org.springframework.test.annotation; +import org.springframework.lang.Nullable; + /** *

    * Strategy interface for retrieving profile values for a given @@ -47,6 +49,7 @@ public interface ProfileValueSource { * @return the String value of the profile value, or {@code null} * if there is no profile value with that key */ + @Nullable String get(String key); } diff --git a/spring-test/src/main/java/org/springframework/test/annotation/ProfileValueUtils.java b/spring-test/src/main/java/org/springframework/test/annotation/ProfileValueUtils.java index 21cfcb14c8..c7dd1a2c1e 100644 --- a/spring-test/src/main/java/org/springframework/test/annotation/ProfileValueUtils.java +++ b/spring-test/src/main/java/org/springframework/test/annotation/ProfileValueUtils.java @@ -23,6 +23,7 @@ import org.apache.commons.logging.LogFactory; import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.core.annotation.AnnotationUtils; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; import org.springframework.util.ReflectionUtils; @@ -176,7 +177,7 @@ public abstract class ProfileValueUtils { * {@code null} */ private static boolean isTestEnabledInThisEnvironment(ProfileValueSource profileValueSource, - IfProfileValue ifProfileValue) { + @Nullable IfProfileValue ifProfileValue) { if (ifProfileValue == null) { return true; diff --git a/spring-test/src/main/java/org/springframework/test/annotation/package-info.java b/spring-test/src/main/java/org/springframework/test/annotation/package-info.java index 1f1f199a66..b2ab125dc2 100644 --- a/spring-test/src/main/java/org/springframework/test/annotation/package-info.java +++ b/spring-test/src/main/java/org/springframework/test/annotation/package-info.java @@ -1,4 +1,7 @@ /** * Support classes for annotation-driven tests. */ +@NonNullApi package org.springframework.test.annotation; + +import org.springframework.lang.NonNullApi; diff --git a/spring-test/src/main/java/org/springframework/test/context/BootstrapUtils.java b/spring-test/src/main/java/org/springframework/test/context/BootstrapUtils.java index 5b81650b7d..4fb45ea539 100644 --- a/spring-test/src/main/java/org/springframework/test/context/BootstrapUtils.java +++ b/spring-test/src/main/java/org/springframework/test/context/BootstrapUtils.java @@ -25,6 +25,7 @@ import org.apache.commons.logging.LogFactory; import org.springframework.beans.BeanUtils; import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.core.annotation.AnnotationAttributes; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; @@ -147,6 +148,7 @@ abstract class BootstrapUtils { } } + @Nullable private static Class resolveExplicitTestContextBootstrapper(Class testClass) { Set annotations = AnnotatedElementUtils.findAllMergedAnnotations(testClass, BootstrapWith.class); if (annotations.size() < 1) { diff --git a/spring-test/src/main/java/org/springframework/test/context/CacheAwareContextLoaderDelegate.java b/spring-test/src/main/java/org/springframework/test/context/CacheAwareContextLoaderDelegate.java index 2771e51493..af10f3890a 100644 --- a/spring-test/src/main/java/org/springframework/test/context/CacheAwareContextLoaderDelegate.java +++ b/spring-test/src/main/java/org/springframework/test/context/CacheAwareContextLoaderDelegate.java @@ -18,6 +18,7 @@ package org.springframework.test.context; import org.springframework.context.ApplicationContext; import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.lang.Nullable; import org.springframework.test.annotation.DirtiesContext.HierarchyMode; /** @@ -69,6 +70,6 @@ public interface CacheAwareContextLoaderDelegate { * is not part of a hierarchy * @since 4.1 */ - void closeContext(MergedContextConfiguration mergedContextConfiguration, HierarchyMode hierarchyMode); + void closeContext(MergedContextConfiguration mergedContextConfiguration, @Nullable HierarchyMode hierarchyMode); } diff --git a/spring-test/src/main/java/org/springframework/test/context/ContextConfigurationAttributes.java b/spring-test/src/main/java/org/springframework/test/context/ContextConfigurationAttributes.java index f32731dfa5..58f0713e66 100644 --- a/spring-test/src/main/java/org/springframework/test/context/ContextConfigurationAttributes.java +++ b/spring-test/src/main/java/org/springframework/test/context/ContextConfigurationAttributes.java @@ -25,6 +25,7 @@ import org.springframework.context.ApplicationContextInitializer; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.core.annotation.AnnotationAttributes; import org.springframework.core.style.ToStringCreator; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; @@ -202,6 +203,7 @@ public class ContextConfigurationAttributes { * @see ContextConfiguration#classes * @see #setClasses(Class[]) */ + @Nullable public Class[] getClasses() { return this.classes; } @@ -237,6 +239,7 @@ public class ContextConfigurationAttributes { * @see ContextConfiguration#locations * @see #setLocations(String[]) */ + @Nullable public String[] getLocations() { return this.locations; } @@ -301,6 +304,7 @@ public class ContextConfigurationAttributes { * @see ContextConfiguration#name() * @since 3.2.2 */ + @Nullable public String getName() { return this.name; } diff --git a/spring-test/src/main/java/org/springframework/test/context/ContextCustomizerFactory.java b/spring-test/src/main/java/org/springframework/test/context/ContextCustomizerFactory.java index 3f8113a6f1..8e0939f34a 100644 --- a/spring-test/src/main/java/org/springframework/test/context/ContextCustomizerFactory.java +++ b/spring-test/src/main/java/org/springframework/test/context/ContextCustomizerFactory.java @@ -18,6 +18,8 @@ package org.springframework.test.context; import java.util.List; +import org.springframework.lang.Nullable; + /** * Factory for creating {@link ContextCustomizer ContextCustomizers}. * @@ -48,6 +50,7 @@ public interface ContextCustomizerFactory { * @return a {@link ContextCustomizer} or {@code null} if no customizer should * be used */ + @Nullable ContextCustomizer createContextCustomizer(Class testClass, List configAttributes); } diff --git a/spring-test/src/main/java/org/springframework/test/context/ContextLoader.java b/spring-test/src/main/java/org/springframework/test/context/ContextLoader.java index 3a2b0c300e..49b97a94aa 100644 --- a/spring-test/src/main/java/org/springframework/test/context/ContextLoader.java +++ b/spring-test/src/main/java/org/springframework/test/context/ContextLoader.java @@ -17,6 +17,7 @@ package org.springframework.test.context; import org.springframework.context.ApplicationContext; +import org.springframework.lang.Nullable; /** * Strategy interface for loading an {@link ApplicationContext application context} @@ -59,7 +60,7 @@ public interface ContextLoader { * application context (can be {@code null} or empty) * @return an array of application context resource locations */ - String[] processLocations(Class clazz, String... locations); + String[] processLocations(Class clazz, @Nullable String... locations); /** * Loads a new {@link ApplicationContext context} based on the supplied diff --git a/spring-test/src/main/java/org/springframework/test/context/MergedContextConfiguration.java b/spring-test/src/main/java/org/springframework/test/context/MergedContextConfiguration.java index c49bbd4579..22aabbcf90 100644 --- a/spring-test/src/main/java/org/springframework/test/context/MergedContextConfiguration.java +++ b/spring-test/src/main/java/org/springframework/test/context/MergedContextConfiguration.java @@ -26,6 +26,7 @@ import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextInitializer; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.core.style.ToStringCreator; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; @@ -134,9 +135,10 @@ public class MergedContextConfiguration implements Serializable { /** * Generate a null-safe {@link String} representation of the supplied * {@link ContextLoader} based solely on the fully qualified name of the - * loader or "null" if the supplied loaded is {@code null}. + * loader or "null" if the supplied loader is {@code null}. */ - protected static String nullSafeToString(ContextLoader contextLoader) { + @Nullable + protected static String nullSafeToString(@Nullable ContextLoader contextLoader) { return (contextLoader != null ? contextLoader.getClass().getName() : "null"); } @@ -197,7 +199,7 @@ public class MergedContextConfiguration implements Serializable { public MergedContextConfiguration(Class testClass, String[] locations, Class[] classes, Set>> contextInitializerClasses, String[] activeProfiles, ContextLoader contextLoader, - CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate, MergedContextConfiguration parent) { + CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate, @Nullable MergedContextConfiguration parent) { this(testClass, locations, classes, contextInitializerClasses, activeProfiles, null, null, contextLoader, cacheAwareContextLoaderDelegate, parent); @@ -238,11 +240,11 @@ public class MergedContextConfiguration implements Serializable { * @param parent the parent configuration or {@code null} if there is no parent * @since 4.1 */ - public MergedContextConfiguration(Class testClass, String[] locations, Class[] classes, - Set>> contextInitializerClasses, - String[] activeProfiles, String[] propertySourceLocations, String[] propertySourceProperties, + public MergedContextConfiguration(Class testClass, @Nullable String[] locations, @Nullable Class[] classes, + @Nullable Set>> contextInitializerClasses, + @Nullable String[] activeProfiles, @Nullable String[] propertySourceLocations, @Nullable String[] propertySourceProperties, ContextLoader contextLoader, CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate, - MergedContextConfiguration parent) { + @Nullable MergedContextConfiguration parent) { this(testClass, locations, classes, contextInitializerClasses, activeProfiles, propertySourceLocations, propertySourceProperties, EMPTY_CONTEXT_CUSTOMIZERS, contextLoader, @@ -273,11 +275,11 @@ public class MergedContextConfiguration implements Serializable { * @param parent the parent configuration or {@code null} if there is no parent * @since 4.3 */ - public MergedContextConfiguration(Class testClass, String[] locations, Class[] classes, - Set>> contextInitializerClasses, - String[] activeProfiles, String[] propertySourceLocations, String[] propertySourceProperties, - Set contextCustomizers, ContextLoader contextLoader, - CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate, MergedContextConfiguration parent) { + public MergedContextConfiguration(Class testClass, @Nullable String[] locations, @Nullable Class[] classes, + @Nullable Set>> contextInitializerClasses, + @Nullable String[] activeProfiles, @Nullable String[] propertySourceLocations, @Nullable String[] propertySourceProperties, + @Nullable Set contextCustomizers, ContextLoader contextLoader, + CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate, @Nullable MergedContextConfiguration parent) { this.testClass = testClass; this.locations = processStrings(locations); @@ -416,6 +418,7 @@ public class MergedContextConfiguration implements Serializable { * @see #getParentApplicationContext() * @since 3.2.2 */ + @Nullable public MergedContextConfiguration getParent() { return this.parent; } @@ -429,6 +432,7 @@ public class MergedContextConfiguration implements Serializable { * @see #getParent() * @since 3.2.2 */ + @Nullable public ApplicationContext getParentApplicationContext() { if (this.parent == null) { return null; diff --git a/spring-test/src/main/java/org/springframework/test/context/TestContext.java b/spring-test/src/main/java/org/springframework/test/context/TestContext.java index 01d9c85658..fa4ae78413 100644 --- a/spring-test/src/main/java/org/springframework/test/context/TestContext.java +++ b/spring-test/src/main/java/org/springframework/test/context/TestContext.java @@ -21,6 +21,7 @@ import java.lang.reflect.Method; import org.springframework.context.ApplicationContext; import org.springframework.core.AttributeAccessor; +import org.springframework.lang.Nullable; import org.springframework.test.annotation.DirtiesContext.HierarchyMode; /** @@ -64,6 +65,7 @@ public interface TestContext extends AttributeAccessor, Serializable { * @return the current test instance (may be {@code null}) * @see #updateState(Object, Method, Throwable) */ + @Nullable Object getTestInstance(); /** @@ -72,6 +74,7 @@ public interface TestContext extends AttributeAccessor, Serializable { * @return the current test method (may be {@code null}) * @see #updateState(Object, Method, Throwable) */ + @Nullable Method getTestMethod(); /** @@ -82,6 +85,7 @@ public interface TestContext extends AttributeAccessor, Serializable { * exception was thrown * @see #updateState(Object, Method, Throwable) */ + @Nullable Throwable getTestException(); /** @@ -94,7 +98,7 @@ public interface TestContext extends AttributeAccessor, Serializable { * @param hierarchyMode the context cache clearing mode to be applied if the * context is part of a hierarchy (may be {@code null}) */ - void markApplicationContextDirty(HierarchyMode hierarchyMode); + void markApplicationContextDirty(@Nullable HierarchyMode hierarchyMode); /** * Update this test context to reflect the state of the currently executing @@ -106,6 +110,6 @@ public interface TestContext extends AttributeAccessor, Serializable { * @param testException the exception that was thrown in the test method, or * {@code null} if no exception was thrown */ - void updateState(Object testInstance, Method testMethod, Throwable testException); + void updateState(@Nullable Object testInstance, @Nullable Method testMethod, @Nullable Throwable testException); } diff --git a/spring-test/src/main/java/org/springframework/test/context/TestContextManager.java b/spring-test/src/main/java/org/springframework/test/context/TestContextManager.java index 1d625d4a93..aa73e664dd 100644 --- a/spring-test/src/main/java/org/springframework/test/context/TestContextManager.java +++ b/spring-test/src/main/java/org/springframework/test/context/TestContextManager.java @@ -25,6 +25,7 @@ import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.ReflectionUtils; @@ -364,7 +365,7 @@ public class TestContextManager { * @see #getTestExecutionListeners() * @see Throwable#addSuppressed(Throwable) */ - public void afterTestExecution(Object testInstance, Method testMethod, Throwable exception) throws Exception { + public void afterTestExecution(Object testInstance, Method testMethod, @Nullable Throwable exception) throws Exception { String callbackName = "afterTestExecution"; prepareForAfterCallback(callbackName, testInstance, testMethod, exception); @@ -424,7 +425,7 @@ public class TestContextManager { * @see #getTestExecutionListeners() * @see Throwable#addSuppressed(Throwable) */ - public void afterTestMethod(Object testInstance, Method testMethod, Throwable exception) throws Exception { + public void afterTestMethod(Object testInstance, Method testMethod, @Nullable Throwable exception) throws Exception { String callbackName = "afterTestMethod"; prepareForAfterCallback(callbackName, testInstance, testMethod, exception); diff --git a/spring-test/src/main/java/org/springframework/test/context/cache/ContextCache.java b/spring-test/src/main/java/org/springframework/test/context/cache/ContextCache.java index 1f15c76301..ea7f5605f8 100644 --- a/spring-test/src/main/java/org/springframework/test/context/cache/ContextCache.java +++ b/spring-test/src/main/java/org/springframework/test/context/cache/ContextCache.java @@ -17,6 +17,7 @@ package org.springframework.test.context.cache; import org.springframework.context.ApplicationContext; +import org.springframework.lang.Nullable; import org.springframework.test.annotation.DirtiesContext.HierarchyMode; import org.springframework.test.context.MergedContextConfiguration; @@ -88,6 +89,7 @@ public interface ContextCache { * if not found in the cache * @see #remove */ + @Nullable ApplicationContext get(MergedContextConfiguration key); /** @@ -112,7 +114,7 @@ public interface ContextCache { * @param hierarchyMode the hierarchy mode; may be {@code null} if the context * is not part of a hierarchy */ - void remove(MergedContextConfiguration key, HierarchyMode hierarchyMode); + void remove(MergedContextConfiguration key, @Nullable HierarchyMode hierarchyMode); /** * Determine the number of contexts currently stored in the cache. diff --git a/spring-test/src/main/java/org/springframework/test/context/cache/package-info.java b/spring-test/src/main/java/org/springframework/test/context/cache/package-info.java index 85fa178450..5529d083ba 100644 --- a/spring-test/src/main/java/org/springframework/test/context/cache/package-info.java +++ b/spring-test/src/main/java/org/springframework/test/context/cache/package-info.java @@ -1,4 +1,7 @@ /** * Support for context caching within the Spring TestContext Framework. */ +@NonNullApi package org.springframework.test.context.cache; + +import org.springframework.lang.NonNullApi; diff --git a/spring-test/src/main/java/org/springframework/test/context/jdbc/package-info.java b/spring-test/src/main/java/org/springframework/test/context/jdbc/package-info.java index eb004d3931..3f3151110b 100644 --- a/spring-test/src/main/java/org/springframework/test/context/jdbc/package-info.java +++ b/spring-test/src/main/java/org/springframework/test/context/jdbc/package-info.java @@ -2,4 +2,7 @@ * JDBC support classes for the Spring TestContext Framework, * including support for declarative SQL script execution via {@code @Sql}. */ +@NonNullApi package org.springframework.test.context.jdbc; + +import org.springframework.lang.NonNullApi; diff --git a/spring-test/src/main/java/org/springframework/test/context/junit/jupiter/ParameterAutowireUtils.java b/spring-test/src/main/java/org/springframework/test/context/junit/jupiter/ParameterAutowireUtils.java index c0fe2c0000..502393e98f 100644 --- a/spring-test/src/main/java/org/springframework/test/context/junit/jupiter/ParameterAutowireUtils.java +++ b/spring-test/src/main/java/org/springframework/test/context/junit/jupiter/ParameterAutowireUtils.java @@ -31,6 +31,7 @@ import org.springframework.context.ApplicationContext; import org.springframework.core.MethodParameter; import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.core.annotation.SynthesizingMethodParameter; +import org.springframework.lang.Nullable; /** * Collection of utilities related to autowiring of individual method parameters. @@ -88,6 +89,7 @@ abstract class ParameterAutowireUtils { * @see SynthesizingMethodParameter#forParameter(Parameter) * @see AutowireCapableBeanFactory#resolveDependency(DependencyDescriptor, String) */ + @Nullable static Object resolveDependency(Parameter parameter, Class containingClass, ApplicationContext applicationContext) { boolean required = findMergedAnnotation(parameter, Autowired.class).map(Autowired::required).orElse(true); MethodParameter methodParameter = SynthesizingMethodParameter.forParameter(parameter); diff --git a/spring-test/src/main/java/org/springframework/test/context/junit/jupiter/package-info.java b/spring-test/src/main/java/org/springframework/test/context/junit/jupiter/package-info.java index ceba54b4f7..d84c10f769 100644 --- a/spring-test/src/main/java/org/springframework/test/context/junit/jupiter/package-info.java +++ b/spring-test/src/main/java/org/springframework/test/context/junit/jupiter/package-info.java @@ -2,4 +2,7 @@ * Core support for integrating the Spring TestContext Framework * with the JUnit Jupiter extension model in JUnit 5. */ +@NonNullApi package org.springframework.test.context.junit.jupiter; + +import org.springframework.lang.NonNullApi; diff --git a/spring-test/src/main/java/org/springframework/test/context/junit/jupiter/web/package-info.java b/spring-test/src/main/java/org/springframework/test/context/junit/jupiter/web/package-info.java index d82b9ceba8..38f765a30d 100644 --- a/spring-test/src/main/java/org/springframework/test/context/junit/jupiter/web/package-info.java +++ b/spring-test/src/main/java/org/springframework/test/context/junit/jupiter/web/package-info.java @@ -2,4 +2,7 @@ * Web support for integrating the Spring TestContext Framework * with the JUnit Jupiter extension model in JUnit 5. */ +@NonNullApi package org.springframework.test.context.junit.jupiter.web; + +import org.springframework.lang.NonNullApi; diff --git a/spring-test/src/main/java/org/springframework/test/context/junit4/SpringJUnit4ClassRunner.java b/spring-test/src/main/java/org/springframework/test/context/junit4/SpringJUnit4ClassRunner.java index dc8c9350c5..6fbb224909 100644 --- a/spring-test/src/main/java/org/springframework/test/context/junit4/SpringJUnit4ClassRunner.java +++ b/spring-test/src/main/java/org/springframework/test/context/junit4/SpringJUnit4ClassRunner.java @@ -36,6 +36,7 @@ import org.junit.runners.model.FrameworkMethod; import org.junit.runners.model.InitializationError; import org.junit.runners.model.Statement; +import org.springframework.lang.Nullable; import org.springframework.test.annotation.ProfileValueUtils; import org.springframework.test.annotation.TestAnnotationUtils; import org.springframework.test.context.TestContextManager; @@ -343,6 +344,7 @@ public class SpringJUnit4ClassRunner extends BlockJUnit4ClassRunner { *

    Can be overridden by subclasses. * @return the expected exception, or {@code null} if none was specified */ + @Nullable protected Class getExpectedException(FrameworkMethod frameworkMethod) { Test test = frameworkMethod.getAnnotation(Test.class); return (test != null && test.expected() != Test.None.class ? test.expected() : null); diff --git a/spring-test/src/main/java/org/springframework/test/context/junit4/package-info.java b/spring-test/src/main/java/org/springframework/test/context/junit4/package-info.java index 0a93b26848..5eb3afdf54 100644 --- a/spring-test/src/main/java/org/springframework/test/context/junit4/package-info.java +++ b/spring-test/src/main/java/org/springframework/test/context/junit4/package-info.java @@ -2,4 +2,7 @@ * Support classes for integrating the Spring TestContext Framework * with JUnit 4.12 or higher. */ +@NonNullApi package org.springframework.test.context.junit4; + +import org.springframework.lang.NonNullApi; diff --git a/spring-test/src/main/java/org/springframework/test/context/junit4/rules/package-info.java b/spring-test/src/main/java/org/springframework/test/context/junit4/rules/package-info.java index 16124c162d..f942e9cdfc 100644 --- a/spring-test/src/main/java/org/springframework/test/context/junit4/rules/package-info.java +++ b/spring-test/src/main/java/org/springframework/test/context/junit4/rules/package-info.java @@ -1,4 +1,7 @@ /** * Custom JUnit {@code Rules} used in the Spring TestContext Framework. */ +@NonNullApi package org.springframework.test.context.junit4.rules; + +import org.springframework.lang.NonNullApi; diff --git a/spring-test/src/main/java/org/springframework/test/context/junit4/statements/ProfileValueChecker.java b/spring-test/src/main/java/org/springframework/test/context/junit4/statements/ProfileValueChecker.java index 5d53bbff71..b665142001 100644 --- a/spring-test/src/main/java/org/springframework/test/context/junit4/statements/ProfileValueChecker.java +++ b/spring-test/src/main/java/org/springframework/test/context/junit4/statements/ProfileValueChecker.java @@ -23,6 +23,7 @@ import org.junit.AssumptionViolatedException; import org.junit.runners.model.Statement; import org.springframework.core.annotation.AnnotatedElementUtils; +import org.springframework.lang.Nullable; import org.springframework.test.annotation.IfProfileValue; import org.springframework.test.annotation.ProfileValueUtils; import org.springframework.util.Assert; @@ -56,7 +57,7 @@ public class ProfileValueChecker extends Statement { * @param testMethod the test method to check; may be {@code null} if * this {@code ProfileValueChecker} is being applied at the class level */ - public ProfileValueChecker(Statement next, Class testClass, Method testMethod) { + public ProfileValueChecker(Statement next, Class testClass, @Nullable Method testMethod) { Assert.notNull(next, "The next statement must not be null"); Assert.notNull(testClass, "The test class must not be null"); this.next = next; diff --git a/spring-test/src/main/java/org/springframework/test/context/junit4/statements/package-info.java b/spring-test/src/main/java/org/springframework/test/context/junit4/statements/package-info.java index 53ce63a089..38a80d3186 100644 --- a/spring-test/src/main/java/org/springframework/test/context/junit4/statements/package-info.java +++ b/spring-test/src/main/java/org/springframework/test/context/junit4/statements/package-info.java @@ -1,4 +1,7 @@ /** * Custom JUnit {@code Statements} used in the Spring TestContext Framework. */ +@NonNullApi package org.springframework.test.context.junit4.statements; + +import org.springframework.lang.NonNullApi; diff --git a/spring-test/src/main/java/org/springframework/test/context/package-info.java b/spring-test/src/main/java/org/springframework/test/context/package-info.java index b20273495c..4b83127f83 100644 --- a/spring-test/src/main/java/org/springframework/test/context/package-info.java +++ b/spring-test/src/main/java/org/springframework/test/context/package-info.java @@ -11,4 +11,7 @@ * and caching, dependency injection of test fixtures, and transactional test * management with default rollback semantics. */ +@NonNullApi package org.springframework.test.context; + +import org.springframework.lang.NonNullApi; diff --git a/spring-test/src/main/java/org/springframework/test/context/support/AbstractContextLoader.java b/spring-test/src/main/java/org/springframework/test/context/support/AbstractContextLoader.java index 31533a8ec3..10a5501b9f 100644 --- a/spring-test/src/main/java/org/springframework/test/context/support/AbstractContextLoader.java +++ b/spring-test/src/main/java/org/springframework/test/context/support/AbstractContextLoader.java @@ -32,6 +32,7 @@ import org.springframework.core.GenericTypeResolver; import org.springframework.core.annotation.AnnotationAwareOrderComparator; import org.springframework.core.env.PropertySource; import org.springframework.core.io.ClassPathResource; +import org.springframework.lang.Nullable; import org.springframework.test.context.ContextConfigurationAttributes; import org.springframework.test.context.ContextCustomizer; import org.springframework.test.context.ContextLoader; @@ -212,7 +213,7 @@ public abstract class AbstractContextLoader implements SmartContextLoader { * @see #processContextConfiguration(ContextConfigurationAttributes) */ @Override - public final String[] processLocations(Class clazz, String... locations) { + public final String[] processLocations(Class clazz, @Nullable String... locations) { return (ObjectUtils.isEmpty(locations) && isGenerateDefaultLocations()) ? generateDefaultLocations(clazz) : modifyLocations(clazz, locations); } diff --git a/spring-test/src/main/java/org/springframework/test/context/support/AbstractDirtiesContextTestExecutionListener.java b/spring-test/src/main/java/org/springframework/test/context/support/AbstractDirtiesContextTestExecutionListener.java index dbf1fa6f71..497722123b 100644 --- a/spring-test/src/main/java/org/springframework/test/context/support/AbstractDirtiesContextTestExecutionListener.java +++ b/spring-test/src/main/java/org/springframework/test/context/support/AbstractDirtiesContextTestExecutionListener.java @@ -23,6 +23,7 @@ import org.apache.commons.logging.LogFactory; import org.springframework.context.ApplicationContext; import org.springframework.core.annotation.AnnotatedElementUtils; +import org.springframework.lang.Nullable; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext.ClassMode; import org.springframework.test.annotation.DirtiesContext.HierarchyMode; @@ -64,7 +65,7 @@ public abstract class AbstractDirtiesContextTestExecutionListener extends Abstra * context is part of a hierarchy; may be {@code null} * @since 3.2.2 */ - protected void dirtyContext(TestContext testContext, HierarchyMode hierarchyMode) { + protected void dirtyContext(TestContext testContext, @Nullable HierarchyMode hierarchyMode) { testContext.markApplicationContextDirty(hierarchyMode); testContext.setAttribute(DependencyInjectionTestExecutionListener.REINJECT_DEPENDENCIES_ATTRIBUTE, Boolean.TRUE); } diff --git a/spring-test/src/main/java/org/springframework/test/context/support/AbstractTestContextBootstrapper.java b/spring-test/src/main/java/org/springframework/test/context/support/AbstractTestContextBootstrapper.java index 376cdaa332..43c62fe490 100644 --- a/spring-test/src/main/java/org/springframework/test/context/support/AbstractTestContextBootstrapper.java +++ b/spring-test/src/main/java/org/springframework/test/context/support/AbstractTestContextBootstrapper.java @@ -34,6 +34,7 @@ import org.springframework.beans.BeanUtils; import org.springframework.core.annotation.AnnotationAwareOrderComparator; import org.springframework.core.annotation.AnnotationUtils; import org.springframework.core.io.support.SpringFactoriesLoader; +import org.springframework.lang.Nullable; import org.springframework.test.context.BootstrapContext; import org.springframework.test.context.CacheAwareContextLoaderDelegate; import org.springframework.test.context.ContextConfiguration; @@ -350,7 +351,7 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot * @see MergedContextConfiguration */ private MergedContextConfiguration buildMergedContextConfiguration(Class testClass, - List configAttributesList, MergedContextConfiguration parentConfig, + List configAttributesList, @Nullable MergedContextConfiguration parentConfig, CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate, boolean requireLocationsClassesOrInitializers) { @@ -490,6 +491,7 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot * @throws IllegalArgumentException if supplied configuration attributes are * {@code null} or empty */ + @Nullable protected Class resolveExplicitContextLoaderClass( List configAttributesList) { diff --git a/spring-test/src/main/java/org/springframework/test/context/support/TestPropertySourceAttributes.java b/spring-test/src/main/java/org/springframework/test/context/support/TestPropertySourceAttributes.java index e2ed3c2c6c..aa18ccfaca 100644 --- a/spring-test/src/main/java/org/springframework/test/context/support/TestPropertySourceAttributes.java +++ b/spring-test/src/main/java/org/springframework/test/context/support/TestPropertySourceAttributes.java @@ -21,6 +21,7 @@ import org.apache.commons.logging.LogFactory; import org.springframework.core.io.ClassPathResource; import org.springframework.core.style.ToStringCreator; +import org.springframework.lang.Nullable; import org.springframework.test.context.TestPropertySource; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; @@ -105,6 +106,7 @@ class TestPropertySourceAttributes { * @see TestPropertySource#locations * @see #setLocations(String[]) */ + @Nullable String[] getLocations() { return locations; } @@ -125,6 +127,7 @@ class TestPropertySourceAttributes { * @return the inlined properties; potentially {@code null} or empty * @see TestPropertySource#properties */ + @Nullable String[] getProperties() { return this.properties; } diff --git a/spring-test/src/main/java/org/springframework/test/context/support/package-info.java b/spring-test/src/main/java/org/springframework/test/context/support/package-info.java index 98630a9bee..769862c129 100644 --- a/spring-test/src/main/java/org/springframework/test/context/support/package-info.java +++ b/spring-test/src/main/java/org/springframework/test/context/support/package-info.java @@ -1,4 +1,7 @@ /** * Support classes for the Spring TestContext Framework. */ +@NonNullApi package org.springframework.test.context.support; + +import org.springframework.lang.NonNullApi; diff --git a/spring-test/src/main/java/org/springframework/test/context/testng/AbstractTestNGSpringContextTests.java b/spring-test/src/main/java/org/springframework/test/context/testng/AbstractTestNGSpringContextTests.java index c36c4e4ca9..01b6bd93d2 100644 --- a/spring-test/src/main/java/org/springframework/test/context/testng/AbstractTestNGSpringContextTests.java +++ b/spring-test/src/main/java/org/springframework/test/context/testng/AbstractTestNGSpringContextTests.java @@ -24,6 +24,7 @@ import org.apache.commons.logging.LogFactory; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; +import org.springframework.lang.Nullable; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestContext; import org.springframework.test.context.TestContextManager; @@ -239,6 +240,7 @@ public abstract class AbstractTestNGSpringContextTests implements IHookable, App return testResultException; } + @Nullable private RuntimeException throwAsUncheckedException(Throwable t) { throwAs(t); diff --git a/spring-test/src/main/java/org/springframework/test/context/testng/package-info.java b/spring-test/src/main/java/org/springframework/test/context/testng/package-info.java index aef08243a5..92208b9e20 100644 --- a/spring-test/src/main/java/org/springframework/test/context/testng/package-info.java +++ b/spring-test/src/main/java/org/springframework/test/context/testng/package-info.java @@ -2,4 +2,7 @@ * Support classes for ApplicationContext-based and transactional * tests run with TestNG and the Spring TestContext Framework. */ +@NonNullApi package org.springframework.test.context.testng; + +import org.springframework.lang.NonNullApi; diff --git a/spring-test/src/main/java/org/springframework/test/context/transaction/TestContextTransactionUtils.java b/spring-test/src/main/java/org/springframework/test/context/transaction/TestContextTransactionUtils.java index b17278e5a0..0a62330774 100644 --- a/spring-test/src/main/java/org/springframework/test/context/transaction/TestContextTransactionUtils.java +++ b/spring-test/src/main/java/org/springframework/test/context/transaction/TestContextTransactionUtils.java @@ -17,6 +17,7 @@ package org.springframework.test.context.transaction; import java.util.Map; + import javax.sql.DataSource; import org.apache.commons.logging.Log; @@ -26,6 +27,7 @@ import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryUtils; import org.springframework.beans.factory.ListableBeanFactory; +import org.springframework.lang.Nullable; import org.springframework.test.context.TestContext; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.annotation.TransactionManagementConfigurer; @@ -86,7 +88,8 @@ public abstract class TestContextTransactionUtils { * @throws BeansException if an error occurs while retrieving an explicitly * named {@code DataSource} */ - public static DataSource retrieveDataSource(TestContext testContext, String name) { + @Nullable + public static DataSource retrieveDataSource(TestContext testContext, @Nullable String name) { Assert.notNull(testContext, "TestContext must not be null"); BeanFactory bf = testContext.getApplicationContext().getAutowireCapableBeanFactory(); @@ -158,7 +161,8 @@ public abstract class TestContextTransactionUtils { * @throws IllegalStateException if more than one TransactionManagementConfigurer * exists in the ApplicationContext */ - public static PlatformTransactionManager retrieveTransactionManager(TestContext testContext, String name) { + @Nullable + public static PlatformTransactionManager retrieveTransactionManager(TestContext testContext, @Nullable String name) { Assert.notNull(testContext, "TestContext must not be null"); BeanFactory bf = testContext.getApplicationContext().getAutowireCapableBeanFactory(); diff --git a/spring-test/src/main/java/org/springframework/test/context/transaction/package-info.java b/spring-test/src/main/java/org/springframework/test/context/transaction/package-info.java index e7ddcdfb27..0828438a38 100644 --- a/spring-test/src/main/java/org/springframework/test/context/transaction/package-info.java +++ b/spring-test/src/main/java/org/springframework/test/context/transaction/package-info.java @@ -1,4 +1,7 @@ /** * Transactional support classes for the Spring TestContext Framework. */ +@NonNullApi package org.springframework.test.context.transaction; + +import org.springframework.lang.NonNullApi; diff --git a/spring-test/src/main/java/org/springframework/test/context/util/package-info.java b/spring-test/src/main/java/org/springframework/test/context/util/package-info.java index 494787df0e..15b97c3d38 100644 --- a/spring-test/src/main/java/org/springframework/test/context/util/package-info.java +++ b/spring-test/src/main/java/org/springframework/test/context/util/package-info.java @@ -1,4 +1,7 @@ /** * Common utilities used within the Spring TestContext Framework. */ +@NonNullApi package org.springframework.test.context.util; + +import org.springframework.lang.NonNullApi; diff --git a/spring-test/src/main/java/org/springframework/test/context/web/WebMergedContextConfiguration.java b/spring-test/src/main/java/org/springframework/test/context/web/WebMergedContextConfiguration.java index 9ed91713c3..a91de16779 100644 --- a/spring-test/src/main/java/org/springframework/test/context/web/WebMergedContextConfiguration.java +++ b/spring-test/src/main/java/org/springframework/test/context/web/WebMergedContextConfiguration.java @@ -21,6 +21,7 @@ import java.util.Set; import org.springframework.context.ApplicationContextInitializer; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.core.style.ToStringCreator; +import org.springframework.lang.Nullable; import org.springframework.test.context.CacheAwareContextLoaderDelegate; import org.springframework.test.context.ContextCustomizer; import org.springframework.test.context.ContextLoader; @@ -97,11 +98,11 @@ public class WebMergedContextConfiguration extends MergedContextConfiguration { * @param parent the parent configuration or {@code null} if there is no parent * @since 4.1 */ - public WebMergedContextConfiguration(Class testClass, String[] locations, Class[] classes, - Set>> contextInitializerClasses, - String[] activeProfiles, String[] propertySourceLocations, String[] propertySourceProperties, + public WebMergedContextConfiguration(Class testClass, @Nullable String[] locations, @Nullable Class[] classes, + @Nullable Set>> contextInitializerClasses, + @Nullable String[] activeProfiles, @Nullable String[] propertySourceLocations, @Nullable String[] propertySourceProperties, String resourceBasePath, ContextLoader contextLoader, - CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate, MergedContextConfiguration parent) { + CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate, @Nullable MergedContextConfiguration parent) { this(testClass, locations, classes, contextInitializerClasses, activeProfiles, propertySourceLocations, propertySourceProperties, null, resourceBasePath, contextLoader, cacheAwareContextLoaderDelegate, parent); @@ -133,11 +134,11 @@ public class WebMergedContextConfiguration extends MergedContextConfiguration { * @param parent the parent configuration or {@code null} if there is no parent * @since 4.3 */ - public WebMergedContextConfiguration(Class testClass, String[] locations, Class[] classes, - Set>> contextInitializerClasses, - String[] activeProfiles, String[] propertySourceLocations, String[] propertySourceProperties, - Set contextCustomizers, String resourceBasePath, ContextLoader contextLoader, - CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate, MergedContextConfiguration parent) { + public WebMergedContextConfiguration(Class testClass, @Nullable String[] locations, @Nullable Class[] classes, + @Nullable Set>> contextInitializerClasses, + @Nullable String[] activeProfiles, @Nullable String[] propertySourceLocations, @Nullable String[] propertySourceProperties, + @Nullable Set contextCustomizers, String resourceBasePath, ContextLoader contextLoader, + CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate, @Nullable MergedContextConfiguration parent) { super(testClass, locations, classes, contextInitializerClasses, activeProfiles, propertySourceLocations, propertySourceProperties, contextCustomizers, contextLoader, cacheAwareContextLoaderDelegate, parent); diff --git a/spring-test/src/main/java/org/springframework/test/context/web/package-info.java b/spring-test/src/main/java/org/springframework/test/context/web/package-info.java index d3dc1c12b5..b45e51670e 100644 --- a/spring-test/src/main/java/org/springframework/test/context/web/package-info.java +++ b/spring-test/src/main/java/org/springframework/test/context/web/package-info.java @@ -1,4 +1,7 @@ /** * Web support classes for the Spring TestContext Framework. */ +@NonNullApi package org.springframework.test.context.web; + +import org.springframework.lang.NonNullApi; diff --git a/spring-test/src/main/java/org/springframework/test/context/web/socket/package-info.java b/spring-test/src/main/java/org/springframework/test/context/web/socket/package-info.java index 7b97278f92..ca6a5942b2 100644 --- a/spring-test/src/main/java/org/springframework/test/context/web/socket/package-info.java +++ b/spring-test/src/main/java/org/springframework/test/context/web/socket/package-info.java @@ -1,4 +1,7 @@ /** * WebSocket support classes for the Spring TestContext Framework. */ +@NonNullApi package org.springframework.test.context.web.socket; + +import org.springframework.lang.NonNullApi; diff --git a/spring-test/src/main/java/org/springframework/test/jdbc/package-info.java b/spring-test/src/main/java/org/springframework/test/jdbc/package-info.java index cfa40b7ed8..d35317061f 100644 --- a/spring-test/src/main/java/org/springframework/test/jdbc/package-info.java +++ b/spring-test/src/main/java/org/springframework/test/jdbc/package-info.java @@ -1,4 +1,7 @@ /** * Support classes for tests based on JDBC. */ +@NonNullApi package org.springframework.test.jdbc; + +import org.springframework.lang.NonNullApi; diff --git a/spring-test/src/main/java/org/springframework/test/util/MetaAnnotationUtils.java b/spring-test/src/main/java/org/springframework/test/util/MetaAnnotationUtils.java index 99dd5125d4..b0f0f03368 100644 --- a/spring-test/src/main/java/org/springframework/test/util/MetaAnnotationUtils.java +++ b/spring-test/src/main/java/org/springframework/test/util/MetaAnnotationUtils.java @@ -24,6 +24,7 @@ import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.core.annotation.AnnotationAttributes; import org.springframework.core.annotation.AnnotationUtils; import org.springframework.core.style.ToStringCreator; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; @@ -80,6 +81,7 @@ public abstract class MetaAnnotationUtils { * @see AnnotationUtils#findAnnotationDeclaringClass(Class, Class) * @see #findAnnotationDescriptorForTypes(Class, Class...) */ + @Nullable public static AnnotationDescriptor findAnnotationDescriptor( Class clazz, Class annotationType) { @@ -96,6 +98,7 @@ public abstract class MetaAnnotationUtils { * @return the corresponding annotation descriptor if the annotation was found; * otherwise {@code null} */ + @Nullable private static AnnotationDescriptor findAnnotationDescriptor( Class clazz, Set visited, Class annotationType) { @@ -165,6 +168,7 @@ public abstract class MetaAnnotationUtils { * @see #findAnnotationDescriptor(Class, Class) */ @SuppressWarnings("unchecked") + @Nullable public static UntypedAnnotationDescriptor findAnnotationDescriptorForTypes( Class clazz, Class... annotationTypes) { @@ -182,6 +186,7 @@ public abstract class MetaAnnotationUtils { * was found; otherwise {@code null} */ @SuppressWarnings("unchecked") + @Nullable private static UntypedAnnotationDescriptor findAnnotationDescriptorForTypes(Class clazz, Set visited, Class... annotationTypes) { diff --git a/spring-test/src/main/java/org/springframework/test/util/ReflectionTestUtils.java b/spring-test/src/main/java/org/springframework/test/util/ReflectionTestUtils.java index 4f508511f5..49864f8412 100644 --- a/spring-test/src/main/java/org/springframework/test/util/ReflectionTestUtils.java +++ b/spring-test/src/main/java/org/springframework/test/util/ReflectionTestUtils.java @@ -22,6 +22,7 @@ import java.lang.reflect.Method; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.MethodInvoker; import org.springframework.util.ObjectUtils; @@ -96,7 +97,7 @@ public class ReflectionTestUtils { * @param type the type of the field to set; may be {@code null} if * {@code name} is specified */ - public static void setField(Object targetObject, String name, Object value, Class type) { + public static void setField(Object targetObject, @Nullable String name, Object value, Class type) { setField(targetObject, null, name, value, type); } @@ -130,7 +131,7 @@ public class ReflectionTestUtils { * {@code name} is specified * @since 4.2 */ - public static void setField(Class targetClass, String name, Object value, Class type) { + public static void setField(Class targetClass, @Nullable String name, Object value, @Nullable Class type) { setField(null, targetClass, name, value, type); } @@ -160,7 +161,7 @@ public class ReflectionTestUtils { * @see ReflectionUtils#setField(Field, Object, Object) * @see AopTestUtils#getUltimateTargetObject(Object) */ - public static void setField(Object targetObject, Class targetClass, String name, Object value, Class type) { + public static void setField(@Nullable Object targetObject, @Nullable Class targetClass, @Nullable String name, Object value, @Nullable Class type) { Assert.isTrue(targetObject != null || targetClass != null, "Either targetObject or targetClass for the field must be specified"); @@ -241,7 +242,7 @@ public class ReflectionTestUtils { * @see ReflectionUtils#getField(Field, Object) * @see AopTestUtils#getUltimateTargetObject(Object) */ - public static Object getField(Object targetObject, Class targetClass, String name) { + public static Object getField(@Nullable Object targetObject, @Nullable Class targetClass, String name) { Assert.isTrue(targetObject != null || targetClass != null, "Either targetObject or targetClass for the field must be specified"); @@ -402,7 +403,8 @@ public class ReflectionTestUtils { * @see ReflectionUtils#handleReflectionException(Exception) */ @SuppressWarnings("unchecked") - public static T invokeMethod(Object target, String name, Object... args) { + @Nullable + public static T invokeMethod(Object target, String name, @Nullable Object... args) { Assert.notNull(target, "Target object must not be null"); Assert.hasText(name, "Method name must not be empty"); diff --git a/spring-test/src/main/java/org/springframework/test/util/XpathExpectationsHelper.java b/spring-test/src/main/java/org/springframework/test/util/XpathExpectationsHelper.java index 524590fac4..89f6c2bf3e 100644 --- a/spring-test/src/main/java/org/springframework/test/util/XpathExpectationsHelper.java +++ b/spring-test/src/main/java/org/springframework/test/util/XpathExpectationsHelper.java @@ -19,6 +19,7 @@ package org.springframework.test.util; import java.io.ByteArrayInputStream; import java.util.Collections; import java.util.Map; + import javax.xml.namespace.QName; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; @@ -34,6 +35,7 @@ import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.xml.sax.InputSource; +import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; import org.springframework.util.xml.SimpleNamespaceContext; @@ -64,7 +66,7 @@ public class XpathExpectationsHelper { * formatting specifiers defined in {@link String#format(String, Object...)} * @throws XPathExpressionException */ - public XpathExpectationsHelper(String expression, Map namespaces, Object... args) + public XpathExpectationsHelper(String expression, @Nullable Map namespaces, Object... args) throws XPathExpressionException { this.expression = String.format(expression, args); diff --git a/spring-test/src/main/java/org/springframework/test/util/package-info.java b/spring-test/src/main/java/org/springframework/test/util/package-info.java index 24a5e21ac2..4794d8b0a6 100644 --- a/spring-test/src/main/java/org/springframework/test/util/package-info.java +++ b/spring-test/src/main/java/org/springframework/test/util/package-info.java @@ -1,4 +1,7 @@ /** * General utility classes for use in unit and integration tests. */ +@NonNullApi package org.springframework.test.util; + +import org.springframework.lang.NonNullApi; diff --git a/spring-test/src/main/java/org/springframework/test/web/client/AbstractRequestExpectationManager.java b/spring-test/src/main/java/org/springframework/test/web/client/AbstractRequestExpectationManager.java index 7b20fdcd3f..d9390b3a7c 100644 --- a/spring-test/src/main/java/org/springframework/test/web/client/AbstractRequestExpectationManager.java +++ b/spring-test/src/main/java/org/springframework/test/web/client/AbstractRequestExpectationManager.java @@ -27,6 +27,7 @@ import java.util.Set; import org.springframework.http.HttpMethod; import org.springframework.http.client.ClientHttpRequest; import org.springframework.http.client.ClientHttpResponse; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -172,6 +173,7 @@ public abstract class AbstractRequestExpectationManager implements RequestExpect } } + @Nullable public RequestExpectation findExpectation(ClientHttpRequest request) throws IOException { for (RequestExpectation expectation : getExpectations()) { try { diff --git a/spring-test/src/main/java/org/springframework/test/web/client/match/XpathRequestMatchers.java b/spring-test/src/main/java/org/springframework/test/web/client/match/XpathRequestMatchers.java index 49255719de..e407ffe79b 100644 --- a/spring-test/src/main/java/org/springframework/test/web/client/match/XpathRequestMatchers.java +++ b/spring-test/src/main/java/org/springframework/test/web/client/match/XpathRequestMatchers.java @@ -18,12 +18,14 @@ package org.springframework.test.web.client.match; import java.io.IOException; import java.util.Map; + import javax.xml.xpath.XPathExpressionException; import org.hamcrest.Matcher; import org.w3c.dom.Node; import org.springframework.http.client.ClientHttpRequest; +import org.springframework.lang.Nullable; import org.springframework.mock.http.client.MockClientHttpRequest; import org.springframework.test.util.XpathExpectationsHelper; import org.springframework.test.web.client.RequestMatcher; @@ -53,7 +55,7 @@ public class XpathRequestMatchers { * formatting specifiers defined in {@link String#format(String, Object...)} * @throws XPathExpressionException */ - protected XpathRequestMatchers(String expression, Map namespaces, Object ... args) + protected XpathRequestMatchers(String expression, @Nullable Map namespaces, Object ... args) throws XPathExpressionException { this.xpathHelper = new XpathExpectationsHelper(expression, namespaces, args); diff --git a/spring-test/src/main/java/org/springframework/test/web/client/match/package-info.java b/spring-test/src/main/java/org/springframework/test/web/client/match/package-info.java index a538c9e009..c76ae81207 100644 --- a/spring-test/src/main/java/org/springframework/test/web/client/match/package-info.java +++ b/spring-test/src/main/java/org/springframework/test/web/client/match/package-info.java @@ -4,4 +4,7 @@ * {@link org.springframework.test.web.client.match.MockRestRequestMatchers} * to gain access to instances of those implementations. */ +@NonNullApi package org.springframework.test.web.client.match; + +import org.springframework.lang.NonNullApi; diff --git a/spring-test/src/main/java/org/springframework/test/web/client/package-info.java b/spring-test/src/main/java/org/springframework/test/web/client/package-info.java index a017790184..615f706a8a 100644 --- a/spring-test/src/main/java/org/springframework/test/web/client/package-info.java +++ b/spring-test/src/main/java/org/springframework/test/web/client/package-info.java @@ -2,4 +2,7 @@ * Contains client-side REST testing support. * @see org.springframework.test.web.client.MockRestServiceServer */ +@NonNullApi package org.springframework.test.web.client; + +import org.springframework.lang.NonNullApi; diff --git a/spring-test/src/main/java/org/springframework/test/web/client/response/MockRestResponseCreators.java b/spring-test/src/main/java/org/springframework/test/web/client/response/MockRestResponseCreators.java index 0ff14df9a1..ac80a4f914 100644 --- a/spring-test/src/main/java/org/springframework/test/web/client/response/MockRestResponseCreators.java +++ b/spring-test/src/main/java/org/springframework/test/web/client/response/MockRestResponseCreators.java @@ -20,6 +20,7 @@ import java.net.URI; import org.springframework.core.io.Resource; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; +import org.springframework.lang.Nullable; import org.springframework.test.web.client.ResponseCreator; /** @@ -45,7 +46,7 @@ public abstract class MockRestResponseCreators { * @param body the response body, a "UTF-8" string * @param mediaType the type of the content, may be {@code null} */ - public static DefaultResponseCreator withSuccess(String body, MediaType mediaType) { + public static DefaultResponseCreator withSuccess(String body, @Nullable MediaType mediaType) { return new DefaultResponseCreator(HttpStatus.OK).body(body).contentType(mediaType); } @@ -54,7 +55,7 @@ public abstract class MockRestResponseCreators { * @param body the response body * @param contentType the type of the content, may be {@code null} */ - public static DefaultResponseCreator withSuccess(byte[] body, MediaType contentType) { + public static DefaultResponseCreator withSuccess(byte[] body, @Nullable MediaType contentType) { return new DefaultResponseCreator(HttpStatus.OK).body(body).contentType(contentType); } @@ -63,7 +64,7 @@ public abstract class MockRestResponseCreators { * @param body the response body * @param contentType the type of the content, may be {@code null} */ - public static DefaultResponseCreator withSuccess(Resource body, MediaType contentType) { + public static DefaultResponseCreator withSuccess(Resource body, @Nullable MediaType contentType) { return new DefaultResponseCreator(HttpStatus.OK).body(body).contentType(contentType); } diff --git a/spring-test/src/main/java/org/springframework/test/web/client/response/package-info.java b/spring-test/src/main/java/org/springframework/test/web/client/response/package-info.java index bc6306c570..4efaa2c5c0 100644 --- a/spring-test/src/main/java/org/springframework/test/web/client/response/package-info.java +++ b/spring-test/src/main/java/org/springframework/test/web/client/response/package-info.java @@ -4,4 +4,7 @@ * {@link org.springframework.test.web.client.response.MockRestResponseCreators} * to gain access to instances of those implementations. */ +@NonNullApi package org.springframework.test.web.client.response; + +import org.springframework.lang.NonNullApi; diff --git a/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClient.java b/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClient.java index b7c23f6d1d..2b2fbb4eca 100644 --- a/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClient.java +++ b/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClient.java @@ -39,6 +39,7 @@ import org.springframework.http.HttpMethod; import org.springframework.http.MediaType; import org.springframework.http.client.reactive.ClientHttpConnector; import org.springframework.http.client.reactive.ClientHttpRequest; +import org.springframework.lang.Nullable; import org.springframework.test.util.JsonExpectationsHelper; import org.springframework.util.Assert; import org.springframework.util.MimeType; @@ -501,6 +502,7 @@ class DefaultWebTestClient implements WebTestClient { return new JsonPathAssertions(this, getBodyAsString(), expression, args); } + @Nullable private String getBodyAsString() { if (this.isEmpty) { return null; diff --git a/spring-test/src/main/java/org/springframework/test/web/reactive/server/package-info.java b/spring-test/src/main/java/org/springframework/test/web/reactive/server/package-info.java index 90489f3f00..47a3a4b6ad 100644 --- a/spring-test/src/main/java/org/springframework/test/web/reactive/server/package-info.java +++ b/spring-test/src/main/java/org/springframework/test/web/reactive/server/package-info.java @@ -2,4 +2,7 @@ * Support for testing Spring WebFlux server endpoints via * {@link org.springframework.test.web.reactive.server.WebTestClient}. */ +@NonNullApi package org.springframework.test.web.reactive.server; + +import org.springframework.lang.NonNullApi; diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/MvcResult.java b/spring-test/src/main/java/org/springframework/test/web/servlet/MvcResult.java index a0676a238e..24f0820385 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/MvcResult.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/MvcResult.java @@ -16,6 +16,7 @@ package org.springframework.test.web.servlet; +import org.springframework.lang.Nullable; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.web.servlet.FlashMap; @@ -47,18 +48,21 @@ public interface MvcResult { * Return the executed handler. * @return the handler, possibly {@code null} if none were executed */ + @Nullable Object getHandler(); /** * Return interceptors around the handler. * @return interceptors, or {@code null} if none were selected */ + @Nullable HandlerInterceptor[] getInterceptors(); /** * Return the {@code ModelAndView} prepared by the handler. * @return a {@code ModelAndView}, or {@code null} */ + @Nullable ModelAndView getModelAndView(); /** @@ -66,6 +70,7 @@ public interface MvcResult { * through a {@link HandlerExceptionResolver}. * @return an exception, possibly {@code null} */ + @Nullable Exception getResolvedException(); /** diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/htmlunit/HtmlUnitRequestBuilder.java b/spring-test/src/main/java/org/springframework/test/web/servlet/htmlunit/HtmlUnitRequestBuilder.java index ba9d6764a4..5f145570e7 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/htmlunit/HtmlUnitRequestBuilder.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/htmlunit/HtmlUnitRequestBuilder.java @@ -42,6 +42,7 @@ import com.gargoylesoftware.htmlunit.util.NameValuePair; import org.springframework.beans.Mergeable; import org.springframework.http.MediaType; +import org.springframework.lang.Nullable; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpSession; import org.springframework.test.web.servlet.RequestBuilder; @@ -206,7 +207,7 @@ final class HtmlUnitRequestBuilder implements RequestBuilder, Mergeable { * @throws IllegalArgumentException if the contextPath is not a valid * {@link HttpServletRequest#getContextPath()} */ - public void setContextPath(String contextPath) { + public void setContextPath(@Nullable String contextPath) { MockMvcWebConnection.validateContextPath(contextPath); this.contextPath = contextPath; } diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/htmlunit/MockMvcWebConnection.java b/spring-test/src/main/java/org/springframework/test/web/servlet/htmlunit/MockMvcWebConnection.java index 6ae42fb18e..657f1546d5 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/htmlunit/MockMvcWebConnection.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/htmlunit/MockMvcWebConnection.java @@ -29,6 +29,7 @@ import com.gargoylesoftware.htmlunit.WebResponse; import com.gargoylesoftware.htmlunit.util.Cookie; import org.apache.http.impl.cookie.BasicClientCookie; +import org.springframework.lang.Nullable; import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.mock.web.MockHttpSession; import org.springframework.test.web.servlet.MockMvc; @@ -90,7 +91,7 @@ public final class MockMvcWebConnection implements WebConnection { * @param webClient the {@link WebClient} to use. never {@code null} * @param contextPath the contextPath to use */ - public MockMvcWebConnection(MockMvc mockMvc, WebClient webClient, String contextPath) { + public MockMvcWebConnection(MockMvc mockMvc, WebClient webClient, @Nullable String contextPath) { Assert.notNull(mockMvc, "MockMvc must not be null"); Assert.notNull(webClient, "WebClient must not be null"); validateContextPath(contextPath); @@ -108,7 +109,7 @@ public final class MockMvcWebConnection implements WebConnection { * a "/" character and not end with a "/" character. * @param contextPath the path to validate */ - static void validateContextPath(String contextPath) { + static void validateContextPath(@Nullable String contextPath) { if (contextPath == null || "".equals(contextPath)) { return; } diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/htmlunit/MockMvcWebConnectionBuilderSupport.java b/spring-test/src/main/java/org/springframework/test/web/servlet/htmlunit/MockMvcWebConnectionBuilderSupport.java index 3edf482474..cb259369a6 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/htmlunit/MockMvcWebConnectionBuilderSupport.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/htmlunit/MockMvcWebConnectionBuilderSupport.java @@ -22,6 +22,7 @@ import java.util.List; import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.WebConnection; +import org.springframework.lang.Nullable; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.htmlunit.DelegatingWebConnection.DelegateWebConnection; import org.springframework.test.web.servlet.setup.MockMvcBuilders; @@ -92,7 +93,7 @@ public abstract class MockMvcWebConnectionBuilderSupport namespaces, Object ... args) + protected XpathResultMatchers(String expression, @Nullable Map namespaces, Object ... args) throws XPathExpressionException { this.xpathHelper = new XpathExpectationsHelper(expression, namespaces, args); diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/result/package-info.java b/spring-test/src/main/java/org/springframework/test/web/servlet/result/package-info.java index 8ee752a27b..26cf583b0c 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/result/package-info.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/result/package-info.java @@ -4,4 +4,7 @@ * and {@link org.springframework.test.web.servlet.result.MockMvcResultHandlers} * to access instances of those implementations. */ +@NonNullApi package org.springframework.test.web.servlet.result; + +import org.springframework.lang.NonNullApi; diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/setup/package-info.java b/spring-test/src/main/java/org/springframework/test/web/servlet/setup/package-info.java index 3244c26dcf..562c7e7f6f 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/setup/package-info.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/setup/package-info.java @@ -3,4 +3,7 @@ * Use {@link org.springframework.test.web.servlet.setup.MockMvcBuilders} * to access to instances of those implementations. */ +@NonNullApi package org.springframework.test.web.servlet.setup; + +import org.springframework.lang.NonNullApi; diff --git a/spring-tx/src/main/java/org/springframework/dao/annotation/package-info.java b/spring-tx/src/main/java/org/springframework/dao/annotation/package-info.java index 962db3dddf..85b1ce0cda 100644 --- a/spring-tx/src/main/java/org/springframework/dao/annotation/package-info.java +++ b/spring-tx/src/main/java/org/springframework/dao/annotation/package-info.java @@ -2,4 +2,7 @@ * Annotation support for DAOs. Contains a bean post-processor for translating * persistence exceptions based on a repository stereotype annotation. */ +@NonNullApi package org.springframework.dao.annotation; + +import org.springframework.lang.NonNullApi; diff --git a/spring-tx/src/main/java/org/springframework/dao/package-info.java b/spring-tx/src/main/java/org/springframework/dao/package-info.java index 4e9a18651e..68478e7d8b 100644 --- a/spring-tx/src/main/java/org/springframework/dao/package-info.java +++ b/spring-tx/src/main/java/org/springframework/dao/package-info.java @@ -13,4 +13,7 @@ * Expert One-On-One J2EE Design and Development * by Rod Johnson (Wrox, 2002). */ +@NonNullApi package org.springframework.dao; + +import org.springframework.lang.NonNullApi; diff --git a/spring-tx/src/main/java/org/springframework/dao/support/DataAccessUtils.java b/spring-tx/src/main/java/org/springframework/dao/support/DataAccessUtils.java index 4d68bd507b..eb255339b8 100644 --- a/spring-tx/src/main/java/org/springframework/dao/support/DataAccessUtils.java +++ b/spring-tx/src/main/java/org/springframework/dao/support/DataAccessUtils.java @@ -22,6 +22,7 @@ import org.springframework.dao.DataAccessException; import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.dao.IncorrectResultSizeDataAccessException; import org.springframework.dao.TypeMismatchDataAccessException; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.util.NumberUtils; @@ -44,6 +45,7 @@ public abstract class DataAccessUtils { * @throws IncorrectResultSizeDataAccessException if more than one * element has been found in the given Collection */ + @Nullable public static T singleResult(Collection results) throws IncorrectResultSizeDataAccessException { int size = (results != null ? results.size() : 0); if (size == 0) { @@ -65,7 +67,7 @@ public abstract class DataAccessUtils { * @throws EmptyResultDataAccessException if no element at all * has been found in the given Collection */ - public static T requiredSingleResult(Collection results) throws IncorrectResultSizeDataAccessException { + public static T requiredSingleResult(@Nullable Collection results) throws IncorrectResultSizeDataAccessException { int size = (results != null ? results.size() : 0); if (size == 0) { throw new EmptyResultDataAccessException(1); @@ -86,7 +88,8 @@ public abstract class DataAccessUtils { * result object has been found in the given Collection * @see org.springframework.util.CollectionUtils#hasUniqueObject */ - public static T uniqueResult(Collection results) throws IncorrectResultSizeDataAccessException { + @Nullable + public static T uniqueResult(@Nullable Collection results) throws IncorrectResultSizeDataAccessException { int size = (results != null ? results.size() : 0); if (size == 0) { return null; @@ -108,7 +111,7 @@ public abstract class DataAccessUtils { * has been found in the given Collection * @see org.springframework.util.CollectionUtils#hasUniqueObject */ - public static T requiredUniqueResult(Collection results) throws IncorrectResultSizeDataAccessException { + public static T requiredUniqueResult(@Nullable Collection results) throws IncorrectResultSizeDataAccessException { int size = (results != null ? results.size() : 0); if (size == 0) { throw new EmptyResultDataAccessException(1); @@ -134,7 +137,7 @@ public abstract class DataAccessUtils { * not match the specified required type */ @SuppressWarnings("unchecked") - public static T objectResult(Collection results, Class requiredType) + public static T objectResult(@Nullable Collection results, Class requiredType) throws IncorrectResultSizeDataAccessException, TypeMismatchDataAccessException { Object result = requiredUniqueResult(results); @@ -172,7 +175,7 @@ public abstract class DataAccessUtils { * @throws TypeMismatchDataAccessException if the unique object * in the collection is not convertible to an int */ - public static int intResult(Collection results) + public static int intResult(@Nullable Collection results) throws IncorrectResultSizeDataAccessException, TypeMismatchDataAccessException { return objectResult(results, Number.class).intValue(); @@ -191,7 +194,7 @@ public abstract class DataAccessUtils { * @throws TypeMismatchDataAccessException if the unique object * in the collection is not convertible to a long */ - public static long longResult(Collection results) + public static long longResult(@Nullable Collection results) throws IncorrectResultSizeDataAccessException, TypeMismatchDataAccessException { return objectResult(results, Number.class).longValue(); diff --git a/spring-tx/src/main/java/org/springframework/dao/support/PersistenceExceptionTranslator.java b/spring-tx/src/main/java/org/springframework/dao/support/PersistenceExceptionTranslator.java index e8351de230..3985818961 100644 --- a/spring-tx/src/main/java/org/springframework/dao/support/PersistenceExceptionTranslator.java +++ b/spring-tx/src/main/java/org/springframework/dao/support/PersistenceExceptionTranslator.java @@ -17,6 +17,7 @@ package org.springframework.dao.support; import org.springframework.dao.DataAccessException; +import org.springframework.lang.Nullable; /** * Interface implemented by Spring integrations with data access technologies @@ -51,6 +52,7 @@ public interface PersistenceExceptionTranslator { * @see org.springframework.dao.DataIntegrityViolationException * @see org.springframework.jdbc.support.SQLExceptionTranslator */ + @Nullable DataAccessException translateExceptionIfPossible(RuntimeException ex); } diff --git a/spring-tx/src/main/java/org/springframework/dao/support/package-info.java b/spring-tx/src/main/java/org/springframework/dao/support/package-info.java index fee1509b04..25f757ab87 100644 --- a/spring-tx/src/main/java/org/springframework/dao/support/package-info.java +++ b/spring-tx/src/main/java/org/springframework/dao/support/package-info.java @@ -2,4 +2,7 @@ * Support classes for DAO implementations, * providing miscellaneous utility methods. */ +@NonNullApi package org.springframework.dao.support; + +import org.springframework.lang.NonNullApi; diff --git a/spring-tx/src/main/java/org/springframework/jca/cci/connection/ConnectionFactoryUtils.java b/spring-tx/src/main/java/org/springframework/jca/cci/connection/ConnectionFactoryUtils.java index 482a8dc0c9..0e0b0479b2 100644 --- a/spring-tx/src/main/java/org/springframework/jca/cci/connection/ConnectionFactoryUtils.java +++ b/spring-tx/src/main/java/org/springframework/jca/cci/connection/ConnectionFactoryUtils.java @@ -25,6 +25,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.jca.cci.CannotGetCciConnectionException; +import org.springframework.lang.Nullable; import org.springframework.transaction.support.ResourceHolderSynchronization; import org.springframework.transaction.support.TransactionSynchronizationManager; import org.springframework.util.Assert; @@ -87,7 +88,7 @@ public abstract class ConnectionFactoryUtils { * if the attempt to get a Connection failed * @see #releaseConnection */ - public static Connection getConnection(ConnectionFactory cf, ConnectionSpec spec) + public static Connection getConnection(ConnectionFactory cf, @Nullable ConnectionSpec spec) throws CannotGetCciConnectionException { try { if (spec != null) { @@ -145,7 +146,7 @@ public abstract class ConnectionFactoryUtils { * (may be {@code null}) * @return whether the Connection is transactional */ - public static boolean isConnectionTransactional(Connection con, ConnectionFactory cf) { + public static boolean isConnectionTransactional(Connection con, @Nullable ConnectionFactory cf) { if (cf == null) { return false; } @@ -162,7 +163,7 @@ public abstract class ConnectionFactoryUtils { * (can be {@code null}) * @see #getConnection */ - public static void releaseConnection(Connection con, ConnectionFactory cf) { + public static void releaseConnection(Connection con, @Nullable ConnectionFactory cf) { try { doReleaseConnection(con, cf); } @@ -186,7 +187,7 @@ public abstract class ConnectionFactoryUtils { * @throws ResourceException if thrown by JCA CCI methods * @see #doGetConnection */ - public static void doReleaseConnection(Connection con, ConnectionFactory cf) throws ResourceException { + public static void doReleaseConnection(Connection con, @Nullable ConnectionFactory cf) throws ResourceException { if (con == null || isConnectionTransactional(con, cf)) { return; } diff --git a/spring-tx/src/main/java/org/springframework/jca/cci/connection/package-info.java b/spring-tx/src/main/java/org/springframework/jca/cci/connection/package-info.java index d53934c18b..6e101b417b 100644 --- a/spring-tx/src/main/java/org/springframework/jca/cci/connection/package-info.java +++ b/spring-tx/src/main/java/org/springframework/jca/cci/connection/package-info.java @@ -3,4 +3,7 @@ * a PlatformTransactionManager for local CCI transactions, * and various simple ConnectionFactory proxies/adapters. */ +@NonNullApi package org.springframework.jca.cci.connection; + +import org.springframework.lang.NonNullApi; diff --git a/spring-tx/src/main/java/org/springframework/jca/cci/core/CciOperations.java b/spring-tx/src/main/java/org/springframework/jca/cci/core/CciOperations.java index 5982c036d1..e06186c3e5 100644 --- a/spring-tx/src/main/java/org/springframework/jca/cci/core/CciOperations.java +++ b/spring-tx/src/main/java/org/springframework/jca/cci/core/CciOperations.java @@ -20,6 +20,7 @@ import javax.resource.cci.InteractionSpec; import javax.resource.cci.Record; import org.springframework.dao.DataAccessException; +import org.springframework.lang.Nullable; /** * Interface that specifies a basic set of CCI operations on an EIS. @@ -47,6 +48,7 @@ public interface CciOperations { * @return the result object returned by the action, if any * @throws DataAccessException if there is any problem */ + @Nullable T execute(ConnectionCallback action) throws DataAccessException; /** @@ -62,6 +64,7 @@ public interface CciOperations { * @return the result object returned by the action, if any * @throws DataAccessException if there is any problem */ + @Nullable T execute(InteractionCallback action) throws DataAccessException; /** diff --git a/spring-tx/src/main/java/org/springframework/jca/cci/core/CciTemplate.java b/spring-tx/src/main/java/org/springframework/jca/cci/core/CciTemplate.java index 4bd46036ca..5480a95cb1 100644 --- a/spring-tx/src/main/java/org/springframework/jca/cci/core/CciTemplate.java +++ b/spring-tx/src/main/java/org/springframework/jca/cci/core/CciTemplate.java @@ -17,6 +17,7 @@ package org.springframework.jca.cci.core; import java.sql.SQLException; + import javax.resource.NotSupportedException; import javax.resource.ResourceException; import javax.resource.cci.Connection; @@ -41,6 +42,7 @@ import org.springframework.jca.cci.InvalidResultSetAccessException; import org.springframework.jca.cci.RecordTypeNotSupportedException; import org.springframework.jca.cci.connection.ConnectionFactoryUtils; import org.springframework.jca.cci.connection.NotSupportedRecordFactory; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -103,7 +105,7 @@ public class CciTemplate implements CciOperations { * @param connectionSpec the CCI ConnectionSpec to obtain Connections for * (may be {@code null}) */ - public CciTemplate(ConnectionFactory connectionFactory, ConnectionSpec connectionSpec) { + public CciTemplate(ConnectionFactory connectionFactory, @Nullable ConnectionSpec connectionSpec) { setConnectionFactory(connectionFactory); setConnectionSpec(connectionSpec); afterPropertiesSet(); @@ -135,6 +137,7 @@ public class CciTemplate implements CciOperations { /** * Return the CCI ConnectionSpec used by this template, if any. */ + @Nullable public ConnectionSpec getConnectionSpec() { return this.connectionSpec; } @@ -158,6 +161,7 @@ public class CciTemplate implements CciOperations { /** * Return a RecordCreator that should be used for creating default output Records. */ + @Nullable public RecordCreator getOutputRecordCreator() { return this.outputRecordCreator; } @@ -267,7 +271,7 @@ public class CciTemplate implements CciOperations { * @throws DataAccessException if there is any problem */ protected T doExecute( - final InteractionSpec spec, final Record inputRecord, final Record outputRecord, + final InteractionSpec spec, final Record inputRecord, @Nullable final Record outputRecord, final RecordExtractor outputExtractor) throws DataAccessException { return execute(new InteractionCallback() { diff --git a/spring-tx/src/main/java/org/springframework/jca/cci/core/ConnectionCallback.java b/spring-tx/src/main/java/org/springframework/jca/cci/core/ConnectionCallback.java index 3729b682e1..ba7f90c07d 100644 --- a/spring-tx/src/main/java/org/springframework/jca/cci/core/ConnectionCallback.java +++ b/spring-tx/src/main/java/org/springframework/jca/cci/core/ConnectionCallback.java @@ -17,11 +17,13 @@ package org.springframework.jca.cci.core; import java.sql.SQLException; + import javax.resource.ResourceException; import javax.resource.cci.Connection; import javax.resource.cci.ConnectionFactory; import org.springframework.dao.DataAccessException; +import org.springframework.lang.Nullable; /** * Generic callback interface for code that operates on a CCI Connection. @@ -70,6 +72,7 @@ public interface ConnectionCallback { * @see javax.resource.cci.ConnectionFactory#getMetaData() * @see CciTemplate#execute(javax.resource.cci.InteractionSpec, RecordCreator, RecordExtractor) */ + @Nullable T doInConnection(Connection connection, ConnectionFactory connectionFactory) throws ResourceException, SQLException, DataAccessException; diff --git a/spring-tx/src/main/java/org/springframework/jca/cci/core/InteractionCallback.java b/spring-tx/src/main/java/org/springframework/jca/cci/core/InteractionCallback.java index d480ca7115..2d404ca6a9 100644 --- a/spring-tx/src/main/java/org/springframework/jca/cci/core/InteractionCallback.java +++ b/spring-tx/src/main/java/org/springframework/jca/cci/core/InteractionCallback.java @@ -17,11 +17,13 @@ package org.springframework.jca.cci.core; import java.sql.SQLException; + import javax.resource.ResourceException; import javax.resource.cci.ConnectionFactory; import javax.resource.cci.Interaction; import org.springframework.dao.DataAccessException; +import org.springframework.lang.Nullable; /** * Generic callback interface for code that operates on a CCI Interaction. @@ -71,6 +73,7 @@ public interface InteractionCallback { * @see javax.resource.cci.ConnectionFactory#getMetaData() * @see CciTemplate#execute(javax.resource.cci.InteractionSpec, RecordCreator, RecordExtractor) */ + @Nullable T doInInteraction(Interaction interaction, ConnectionFactory connectionFactory) throws ResourceException, SQLException, DataAccessException; diff --git a/spring-tx/src/main/java/org/springframework/jca/cci/core/RecordExtractor.java b/spring-tx/src/main/java/org/springframework/jca/cci/core/RecordExtractor.java index 058689707d..f5714fa63e 100644 --- a/spring-tx/src/main/java/org/springframework/jca/cci/core/RecordExtractor.java +++ b/spring-tx/src/main/java/org/springframework/jca/cci/core/RecordExtractor.java @@ -17,10 +17,12 @@ package org.springframework.jca.cci.core; import java.sql.SQLException; + import javax.resource.ResourceException; import javax.resource.cci.Record; import org.springframework.dao.DataAccessException; +import org.springframework.lang.Nullable; /** * Callback interface for extracting a result object from a CCI Record instance. @@ -58,6 +60,7 @@ public interface RecordExtractor { * @throws DataAccessException in case of custom exceptions * @see javax.resource.cci.ResultSet */ + @Nullable T extractData(Record record) throws ResourceException, SQLException, DataAccessException; } diff --git a/spring-tx/src/main/java/org/springframework/jca/cci/core/package-info.java b/spring-tx/src/main/java/org/springframework/jca/cci/core/package-info.java index 2355d8e16b..df593e88c5 100644 --- a/spring-tx/src/main/java/org/springframework/jca/cci/core/package-info.java +++ b/spring-tx/src/main/java/org/springframework/jca/cci/core/package-info.java @@ -2,4 +2,7 @@ * Provides the core JCA CCI support, based on CciTemplate * and its associated callback interfaces. */ +@NonNullApi package org.springframework.jca.cci.core; + +import org.springframework.lang.NonNullApi; diff --git a/spring-tx/src/main/java/org/springframework/jca/cci/core/support/package-info.java b/spring-tx/src/main/java/org/springframework/jca/cci/core/support/package-info.java index c32695212f..46d9e5f6e4 100644 --- a/spring-tx/src/main/java/org/springframework/jca/cci/core/support/package-info.java +++ b/spring-tx/src/main/java/org/springframework/jca/cci/core/support/package-info.java @@ -2,4 +2,7 @@ * Classes supporting the {@code org.springframework.jca.cci.core} package. * Contains a DAO base class for CciTemplate usage. */ +@NonNullApi package org.springframework.jca.cci.core.support; + +import org.springframework.lang.NonNullApi; diff --git a/spring-tx/src/main/java/org/springframework/jca/cci/object/package-info.java b/spring-tx/src/main/java/org/springframework/jca/cci/object/package-info.java index caace5c3c5..9369900c21 100644 --- a/spring-tx/src/main/java/org/springframework/jca/cci/object/package-info.java +++ b/spring-tx/src/main/java/org/springframework/jca/cci/object/package-info.java @@ -5,4 +5,7 @@ * Exceptions thrown are as in the {@code org.springframework.dao} package, * meaning that code using this package does not need to worry about error handling. */ +@NonNullApi package org.springframework.jca.cci.object; + +import org.springframework.lang.NonNullApi; diff --git a/spring-tx/src/main/java/org/springframework/jca/cci/package-info.java b/spring-tx/src/main/java/org/springframework/jca/cci/package-info.java index a47904f235..7c1fd13c79 100644 --- a/spring-tx/src/main/java/org/springframework/jca/cci/package-info.java +++ b/spring-tx/src/main/java/org/springframework/jca/cci/package-info.java @@ -4,4 +4,7 @@ * to the {@code org.springframework.jdbc} package, providing the same * levels of data access abstraction. */ +@NonNullApi package org.springframework.jca.cci; + +import org.springframework.lang.NonNullApi; diff --git a/spring-tx/src/main/java/org/springframework/jca/context/SpringContextResourceAdapter.java b/spring-tx/src/main/java/org/springframework/jca/context/SpringContextResourceAdapter.java index 04b6e3ac02..0c0dcf1e5c 100644 --- a/spring-tx/src/main/java/org/springframework/jca/context/SpringContextResourceAdapter.java +++ b/spring-tx/src/main/java/org/springframework/jca/context/SpringContextResourceAdapter.java @@ -33,6 +33,7 @@ import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.StandardEnvironment; +import org.springframework.lang.Nullable; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; @@ -230,6 +231,7 @@ public class SpringContextResourceAdapter implements ResourceAdapter { * This implementation always returns {@code null}. */ @Override + @Nullable public XAResource[] getXAResources(ActivationSpec[] activationSpecs) throws ResourceException { return null; } diff --git a/spring-tx/src/main/java/org/springframework/jca/context/package-info.java b/spring-tx/src/main/java/org/springframework/jca/context/package-info.java index c3b2f62e56..bb4dc6fdfd 100644 --- a/spring-tx/src/main/java/org/springframework/jca/context/package-info.java +++ b/spring-tx/src/main/java/org/springframework/jca/context/package-info.java @@ -2,4 +2,7 @@ * Integration package that allows for deploying a Spring application context * as a JCA 1.7 compliant RAR file. */ +@NonNullApi package org.springframework.jca.context; + +import org.springframework.lang.NonNullApi; diff --git a/spring-tx/src/main/java/org/springframework/jca/endpoint/AbstractMessageEndpointFactory.java b/spring-tx/src/main/java/org/springframework/jca/endpoint/AbstractMessageEndpointFactory.java index 5f7883e0aa..893e2d8c5c 100644 --- a/spring-tx/src/main/java/org/springframework/jca/endpoint/AbstractMessageEndpointFactory.java +++ b/spring-tx/src/main/java/org/springframework/jca/endpoint/AbstractMessageEndpointFactory.java @@ -30,6 +30,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.BeanNameAware; +import org.springframework.lang.Nullable; import org.springframework.transaction.jta.SimpleTransactionFactory; import org.springframework.transaction.jta.TransactionFactory; @@ -135,6 +136,7 @@ public abstract class AbstractMessageEndpointFactory implements MessageEndpointF * @see #setBeanName */ @Override + @Nullable public String getActivationName() { return this.beanName; } @@ -144,6 +146,7 @@ public abstract class AbstractMessageEndpointFactory implements MessageEndpointF * returning {@code} null in order to indicate a synthetic endpoint type. */ @Override + @Nullable public Class getEndpointClass() { return null; } diff --git a/spring-tx/src/main/java/org/springframework/jca/endpoint/package-info.java b/spring-tx/src/main/java/org/springframework/jca/endpoint/package-info.java index 5a1a7cde69..fe6beaa826 100644 --- a/spring-tx/src/main/java/org/springframework/jca/endpoint/package-info.java +++ b/spring-tx/src/main/java/org/springframework/jca/endpoint/package-info.java @@ -1,4 +1,7 @@ /** * This package provides a facility for generic JCA message endpoint management. */ +@NonNullApi package org.springframework.jca.endpoint; + +import org.springframework.lang.NonNullApi; diff --git a/spring-tx/src/main/java/org/springframework/jca/support/SimpleBootstrapContext.java b/spring-tx/src/main/java/org/springframework/jca/support/SimpleBootstrapContext.java index 3cca326ea3..1ecfd9be86 100644 --- a/spring-tx/src/main/java/org/springframework/jca/support/SimpleBootstrapContext.java +++ b/spring-tx/src/main/java/org/springframework/jca/support/SimpleBootstrapContext.java @@ -17,6 +17,7 @@ package org.springframework.jca.support; import java.util.Timer; + import javax.resource.spi.BootstrapContext; import javax.resource.spi.UnavailableException; import javax.resource.spi.XATerminator; @@ -24,6 +25,8 @@ import javax.resource.spi.work.WorkContext; import javax.resource.spi.work.WorkManager; import javax.transaction.TransactionSynchronizationRegistry; +import org.springframework.lang.Nullable; + /** * Simple implementation of the JCA 1.7 {@link javax.resource.spi.BootstrapContext} * interface, used for bootstrapping a JCA ResourceAdapter in a local environment. @@ -50,7 +53,7 @@ public class SimpleBootstrapContext implements BootstrapContext { * with no XATerminator available. * @param workManager the JCA WorkManager to use (may be {@code null}) */ - public SimpleBootstrapContext(WorkManager workManager) { + public SimpleBootstrapContext(@Nullable WorkManager workManager) { this.workManager = workManager; } @@ -59,7 +62,7 @@ public class SimpleBootstrapContext implements BootstrapContext { * @param workManager the JCA WorkManager to use (may be {@code null}) * @param xaTerminator the JCA XATerminator to use (may be {@code null}) */ - public SimpleBootstrapContext(WorkManager workManager, XATerminator xaTerminator) { + public SimpleBootstrapContext(@Nullable WorkManager workManager, @Nullable XATerminator xaTerminator) { this.workManager = workManager; this.xaTerminator = xaTerminator; } @@ -73,8 +76,8 @@ public class SimpleBootstrapContext implements BootstrapContext { * to use (may be {@code null}) * @since 5.0 */ - public SimpleBootstrapContext(WorkManager workManager, XATerminator xaTerminator, - TransactionSynchronizationRegistry transactionSynchronizationRegistry) { + public SimpleBootstrapContext(@Nullable WorkManager workManager, @Nullable XATerminator xaTerminator, + @Nullable TransactionSynchronizationRegistry transactionSynchronizationRegistry) { this.workManager = workManager; this.xaTerminator = xaTerminator; diff --git a/spring-tx/src/main/java/org/springframework/jca/support/package-info.java b/spring-tx/src/main/java/org/springframework/jca/support/package-info.java index 133f84dacb..9abe8fb34a 100644 --- a/spring-tx/src/main/java/org/springframework/jca/support/package-info.java +++ b/spring-tx/src/main/java/org/springframework/jca/support/package-info.java @@ -2,4 +2,7 @@ * Provides generic support classes for JCA usage within Spring, * mainly for local setup of a JCA ResourceAdapter and/or ConnectionFactory. */ +@NonNullApi package org.springframework.jca.support; + +import org.springframework.lang.NonNullApi; diff --git a/spring-tx/src/main/java/org/springframework/jca/work/WorkManagerTaskExecutor.java b/spring-tx/src/main/java/org/springframework/jca/work/WorkManagerTaskExecutor.java index 6f9aaa5bc5..5aafc72b54 100644 --- a/spring-tx/src/main/java/org/springframework/jca/work/WorkManagerTaskExecutor.java +++ b/spring-tx/src/main/java/org/springframework/jca/work/WorkManagerTaskExecutor.java @@ -35,6 +35,7 @@ import org.springframework.core.task.TaskRejectedException; import org.springframework.core.task.TaskTimeoutException; import org.springframework.jca.context.BootstrapContextAware; import org.springframework.jndi.JndiLocatorSupport; +import org.springframework.lang.Nullable; import org.springframework.scheduling.SchedulingException; import org.springframework.scheduling.SchedulingTaskExecutor; import org.springframework.util.Assert; @@ -157,7 +158,7 @@ public class WorkManagerTaskExecutor extends JndiLocatorSupport *

    This shared WorkListener instance will be passed on to the * WorkManager by all {@link #execute} calls on this TaskExecutor. */ - public void setWorkListener(WorkListener workListener) { + public void setWorkListener(@Nullable WorkListener workListener) { this.workListener = workListener; } diff --git a/spring-tx/src/main/java/org/springframework/jca/work/package-info.java b/spring-tx/src/main/java/org/springframework/jca/work/package-info.java index ef83b0e3ba..4a0eb0ca87 100644 --- a/spring-tx/src/main/java/org/springframework/jca/work/package-info.java +++ b/spring-tx/src/main/java/org/springframework/jca/work/package-info.java @@ -2,4 +2,7 @@ * Convenience classes for scheduling based on the JCA WorkManager facility, * as supported within ResourceAdapters. */ +@NonNullApi package org.springframework.jca.work; + +import org.springframework.lang.NonNullApi; diff --git a/spring-tx/src/main/java/org/springframework/transaction/PlatformTransactionManager.java b/spring-tx/src/main/java/org/springframework/transaction/PlatformTransactionManager.java index 2c2030f6bc..ad5512c3bf 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/PlatformTransactionManager.java +++ b/spring-tx/src/main/java/org/springframework/transaction/PlatformTransactionManager.java @@ -16,6 +16,8 @@ package org.springframework.transaction; +import org.springframework.lang.Nullable; + /** * This is the central interface in Spring's transaction infrastructure. * Applications can use this directly, but it is not primarily meant as API: @@ -66,7 +68,7 @@ public interface PlatformTransactionManager { * @see TransactionDefinition#getTimeout * @see TransactionDefinition#isReadOnly */ - TransactionStatus getTransaction(TransactionDefinition definition) throws TransactionException; + TransactionStatus getTransaction(@Nullable TransactionDefinition definition) throws TransactionException; /** * Commit the given transaction, with regard to its status. If the transaction diff --git a/spring-tx/src/main/java/org/springframework/transaction/TransactionDefinition.java b/spring-tx/src/main/java/org/springframework/transaction/TransactionDefinition.java index a45c096e1b..84d75f3498 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/TransactionDefinition.java +++ b/spring-tx/src/main/java/org/springframework/transaction/TransactionDefinition.java @@ -18,6 +18,8 @@ package org.springframework.transaction; import java.sql.Connection; +import org.springframework.lang.Nullable; + /** * Interface that defines Spring-compliant transaction properties. * Based on the propagation behavior definitions analogous to EJB CMT attributes. @@ -253,6 +255,7 @@ public interface TransactionDefinition { * @see org.springframework.transaction.interceptor.TransactionAspectSupport * @see org.springframework.transaction.support.TransactionSynchronizationManager#getCurrentTransactionName() */ + @Nullable String getName(); } diff --git a/spring-tx/src/main/java/org/springframework/transaction/TransactionSystemException.java b/spring-tx/src/main/java/org/springframework/transaction/TransactionSystemException.java index 2af9b448ce..24c1248876 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/TransactionSystemException.java +++ b/spring-tx/src/main/java/org/springframework/transaction/TransactionSystemException.java @@ -16,6 +16,7 @@ package org.springframework.transaction; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -69,6 +70,7 @@ public class TransactionSystemException extends TransactionException { * if any. * @return the application exception, or {@code null} if none set */ + @Nullable public final Throwable getApplicationException() { return this.applicationException; } @@ -78,6 +80,7 @@ public class TransactionSystemException extends TransactionException { * i.e. the application exception, if any, or the TransactionSystemException's own cause. * @return the original exception, or {@code null} if there was none */ + @Nullable public Throwable getOriginalException() { return (this.applicationException != null ? this.applicationException : getCause()); } diff --git a/spring-tx/src/main/java/org/springframework/transaction/annotation/AnnotationTransactionAttributeSource.java b/spring-tx/src/main/java/org/springframework/transaction/annotation/AnnotationTransactionAttributeSource.java index 08722d5b4b..53c23a14a4 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/annotation/AnnotationTransactionAttributeSource.java +++ b/spring-tx/src/main/java/org/springframework/transaction/annotation/AnnotationTransactionAttributeSource.java @@ -23,6 +23,7 @@ import java.util.Collections; import java.util.LinkedHashSet; import java.util.Set; +import org.springframework.lang.Nullable; import org.springframework.transaction.interceptor.AbstractFallbackTransactionAttributeSource; import org.springframework.transaction.interceptor.TransactionAttribute; import org.springframework.util.Assert; @@ -149,6 +150,7 @@ public class AnnotationTransactionAttributeSource extends AbstractFallbackTransa * @return TransactionAttribute the configured transaction attribute, * or {@code null} if none was found */ + @Nullable protected TransactionAttribute determineTransactionAttribute(AnnotatedElement ae) { for (TransactionAnnotationParser annotationParser : this.annotationParsers) { TransactionAttribute attr = annotationParser.parseTransactionAnnotation(ae); diff --git a/spring-tx/src/main/java/org/springframework/transaction/annotation/TransactionAnnotationParser.java b/spring-tx/src/main/java/org/springframework/transaction/annotation/TransactionAnnotationParser.java index 558b464028..c47c86ba8d 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/annotation/TransactionAnnotationParser.java +++ b/spring-tx/src/main/java/org/springframework/transaction/annotation/TransactionAnnotationParser.java @@ -18,6 +18,7 @@ package org.springframework.transaction.annotation; import java.lang.reflect.AnnotatedElement; +import org.springframework.lang.Nullable; import org.springframework.transaction.interceptor.TransactionAttribute; /** @@ -47,6 +48,7 @@ public interface TransactionAnnotationParser { * or {@code null} if none was found * @see AnnotationTransactionAttributeSource#determineTransactionAttribute */ + @Nullable TransactionAttribute parseTransactionAnnotation(AnnotatedElement ae); } diff --git a/spring-tx/src/main/java/org/springframework/transaction/annotation/package-info.java b/spring-tx/src/main/java/org/springframework/transaction/annotation/package-info.java index 152819a3b8..77626fb012 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/annotation/package-info.java +++ b/spring-tx/src/main/java/org/springframework/transaction/annotation/package-info.java @@ -3,4 +3,7 @@ * Hooked into Spring's transaction interception infrastructure * via a special TransactionAttributeSource implementation. */ +@NonNullApi package org.springframework.transaction.annotation; + +import org.springframework.lang.NonNullApi; diff --git a/spring-tx/src/main/java/org/springframework/transaction/config/package-info.java b/spring-tx/src/main/java/org/springframework/transaction/config/package-info.java index 32af9ae1ce..4b3b82bdf5 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/config/package-info.java +++ b/spring-tx/src/main/java/org/springframework/transaction/config/package-info.java @@ -2,4 +2,7 @@ * Support package for declarative transaction configuration, * with XML schema being the primary configuration format. */ +@NonNullApi package org.springframework.transaction.config; + +import org.springframework.lang.NonNullApi; diff --git a/spring-tx/src/main/java/org/springframework/transaction/event/package-info.java b/spring-tx/src/main/java/org/springframework/transaction/event/package-info.java index 037c8e0324..a5fcfd7131 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/event/package-info.java +++ b/spring-tx/src/main/java/org/springframework/transaction/event/package-info.java @@ -1,4 +1,7 @@ /** * Spring's support for listening to transaction events. */ +@NonNullApi package org.springframework.transaction.event; + +import org.springframework.lang.NonNullApi; diff --git a/spring-tx/src/main/java/org/springframework/transaction/interceptor/AbstractFallbackTransactionAttributeSource.java b/spring-tx/src/main/java/org/springframework/transaction/interceptor/AbstractFallbackTransactionAttributeSource.java index b1c310f1c6..aad08eecc3 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/interceptor/AbstractFallbackTransactionAttributeSource.java +++ b/spring-tx/src/main/java/org/springframework/transaction/interceptor/AbstractFallbackTransactionAttributeSource.java @@ -26,6 +26,7 @@ import org.apache.commons.logging.LogFactory; import org.springframework.core.BridgeMethodResolver; import org.springframework.core.MethodClassKey; +import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; /** @@ -81,7 +82,7 @@ public abstract class AbstractFallbackTransactionAttributeSource implements Tran * is not transactional */ @Override - public TransactionAttribute getTransactionAttribute(Method method, Class targetClass) { + public TransactionAttribute getTransactionAttribute(Method method, @Nullable Class targetClass) { if (method.getDeclaringClass() == Object.class) { return null; } @@ -128,7 +129,7 @@ public abstract class AbstractFallbackTransactionAttributeSource implements Tran * @param targetClass the target class (may be {@code null}) * @return the cache key (never {@code null}) */ - protected Object getCacheKey(Method method, Class targetClass) { + protected Object getCacheKey(Method method, @Nullable Class targetClass) { return new MethodClassKey(method, targetClass); } @@ -139,6 +140,7 @@ public abstract class AbstractFallbackTransactionAttributeSource implements Tran * @since 4.1.8 * @see #getTransactionAttribute */ + @Nullable protected TransactionAttribute computeTransactionAttribute(Method method, Class targetClass) { // Don't allow no-public methods as required. if (allowPublicMethodsOnly() && !Modifier.isPublic(method.getModifiers())) { @@ -189,6 +191,7 @@ public abstract class AbstractFallbackTransactionAttributeSource implements Tran * @return all transaction attribute associated with this method * (or {@code null} if none) */ + @Nullable protected abstract TransactionAttribute findTransactionAttribute(Method method); /** @@ -198,6 +201,7 @@ public abstract class AbstractFallbackTransactionAttributeSource implements Tran * @return all transaction attribute associated with this class * (or {@code null} if none) */ + @Nullable protected abstract TransactionAttribute findTransactionAttribute(Class clazz); diff --git a/spring-tx/src/main/java/org/springframework/transaction/interceptor/DefaultTransactionAttribute.java b/spring-tx/src/main/java/org/springframework/transaction/interceptor/DefaultTransactionAttribute.java index fc45334c03..753f6b25df 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/interceptor/DefaultTransactionAttribute.java +++ b/spring-tx/src/main/java/org/springframework/transaction/interceptor/DefaultTransactionAttribute.java @@ -16,6 +16,7 @@ package org.springframework.transaction.interceptor; +import org.springframework.lang.Nullable; import org.springframework.transaction.support.DefaultTransactionDefinition; /** @@ -106,6 +107,7 @@ public class DefaultTransactionAttribute extends DefaultTransactionDefinition im * or {@code null} if none. * @since 4.3.4 */ + @Nullable public String getDescriptor() { return this.descriptor; } diff --git a/spring-tx/src/main/java/org/springframework/transaction/interceptor/TransactionAspectSupport.java b/spring-tx/src/main/java/org/springframework/transaction/interceptor/TransactionAspectSupport.java index 035cfaab80..3180254eaa 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/interceptor/TransactionAspectSupport.java +++ b/spring-tx/src/main/java/org/springframework/transaction/interceptor/TransactionAspectSupport.java @@ -28,6 +28,7 @@ import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.annotation.BeanFactoryAnnotationUtils; import org.springframework.core.NamedThreadLocal; +import org.springframework.lang.Nullable; import org.springframework.transaction.NoTransactionException; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.TransactionStatus; @@ -105,6 +106,7 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init * @see org.springframework.transaction.support.TransactionSynchronizationManager#isSynchronizationActive() * @see org.springframework.transaction.support.TransactionSynchronizationManager#isActualTransactionActive() */ + @Nullable protected static TransactionInfo currentTransactionInfo() throws NoTransactionException { return transactionInfoHolder.get(); } @@ -167,6 +169,7 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init /** * Return the default transaction manager, or {@code null} if unknown. */ + @Nullable public PlatformTransactionManager getTransactionManager() { return this.transactionManager; } @@ -264,6 +267,7 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init * @return the return value of the method, if any * @throws Throwable propagated from the target invocation */ + @Nullable protected Object invokeWithinTransaction(Method method, Class targetClass, final InvocationCallback invocation) throws Throwable { @@ -411,6 +415,7 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init * @return a String representation identifying this method * @see org.springframework.util.ClassUtils#getQualifiedMethodName */ + @Nullable protected String methodIdentification(Method method, Class targetClass) { return null; } @@ -429,7 +434,7 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init */ @SuppressWarnings("serial") protected TransactionInfo createTransactionIfNecessary( - PlatformTransactionManager tm, TransactionAttribute txAttr, final String joinpointIdentification) { + PlatformTransactionManager tm, @Nullable TransactionAttribute txAttr, final String joinpointIdentification) { // If no name specified, apply method identification as transaction name. if (txAttr != null && txAttr.getName() == null) { @@ -465,7 +470,7 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init * @return the prepared TransactionInfo object */ protected TransactionInfo prepareTransactionInfo(PlatformTransactionManager tm, - TransactionAttribute txAttr, String joinpointIdentification, TransactionStatus status) { + @Nullable TransactionAttribute txAttr, String joinpointIdentification, TransactionStatus status) { TransactionInfo txInfo = new TransactionInfo(tm, txAttr, joinpointIdentification); if (txAttr != null) { @@ -563,7 +568,7 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init *

    Call this in all cases: exception or normal return! * @param txInfo information about the current transaction (may be {@code null}) */ - protected void cleanupTransactionInfo(TransactionInfo txInfo) { + protected void cleanupTransactionInfo(@Nullable TransactionInfo txInfo) { if (txInfo != null) { txInfo.restoreThreadLocalStatus(); } diff --git a/spring-tx/src/main/java/org/springframework/transaction/interceptor/TransactionAttributeSource.java b/spring-tx/src/main/java/org/springframework/transaction/interceptor/TransactionAttributeSource.java index a6a9250fce..6d0c3dee00 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/interceptor/TransactionAttributeSource.java +++ b/spring-tx/src/main/java/org/springframework/transaction/interceptor/TransactionAttributeSource.java @@ -18,6 +18,8 @@ package org.springframework.transaction.interceptor; import java.lang.reflect.Method; +import org.springframework.lang.Nullable; + /** * Strategy interface used by {@link TransactionInterceptor} for metadata retrieval. * @@ -41,6 +43,7 @@ public interface TransactionAttributeSource { * @return TransactionAttribute the matching transaction attribute, * or {@code null} if none found */ - TransactionAttribute getTransactionAttribute(Method method, Class targetClass); + @Nullable + TransactionAttribute getTransactionAttribute(Method method, @Nullable Class targetClass); } diff --git a/spring-tx/src/main/java/org/springframework/transaction/interceptor/TransactionAttributeSourcePointcut.java b/spring-tx/src/main/java/org/springframework/transaction/interceptor/TransactionAttributeSourcePointcut.java index fa6d9e1ac6..d82040f20c 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/interceptor/TransactionAttributeSourcePointcut.java +++ b/spring-tx/src/main/java/org/springframework/transaction/interceptor/TransactionAttributeSourcePointcut.java @@ -20,6 +20,7 @@ import java.io.Serializable; import java.lang.reflect.Method; import org.springframework.aop.support.StaticMethodMatcherPointcut; +import org.springframework.lang.Nullable; import org.springframework.util.ObjectUtils; /** @@ -68,6 +69,7 @@ abstract class TransactionAttributeSourcePointcut extends StaticMethodMatcherPoi * Obtain the underlying TransactionAttributeSource (may be {@code null}). * To be implemented by subclasses. */ + @Nullable protected abstract TransactionAttributeSource getTransactionAttributeSource(); } diff --git a/spring-tx/src/main/java/org/springframework/transaction/interceptor/package-info.java b/spring-tx/src/main/java/org/springframework/transaction/interceptor/package-info.java index a34f97db97..70cf07abf9 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/interceptor/package-info.java +++ b/spring-tx/src/main/java/org/springframework/transaction/interceptor/package-info.java @@ -11,4 +11,7 @@ * This allows declarative transaction management in any environment, * even without JTA if an application uses only a single database. */ +@NonNullApi package org.springframework.transaction.interceptor; + +import org.springframework.lang.NonNullApi; diff --git a/spring-tx/src/main/java/org/springframework/transaction/jta/JtaTransactionManager.java b/spring-tx/src/main/java/org/springframework/transaction/jta/JtaTransactionManager.java index 4d46ebbca0..4be8ba19c3 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/jta/JtaTransactionManager.java +++ b/spring-tx/src/main/java/org/springframework/transaction/jta/JtaTransactionManager.java @@ -21,6 +21,7 @@ import java.io.ObjectInputStream; import java.io.Serializable; import java.util.List; import java.util.Properties; + import javax.naming.NamingException; import javax.transaction.HeuristicMixedException; import javax.transaction.HeuristicRollbackException; @@ -36,6 +37,7 @@ import javax.transaction.UserTransaction; import org.springframework.beans.factory.InitializingBean; import org.springframework.jndi.JndiTemplate; +import org.springframework.lang.Nullable; import org.springframework.transaction.CannotCreateTransactionException; import org.springframework.transaction.HeuristicCompletionException; import org.springframework.transaction.IllegalTransactionStateException; @@ -331,6 +333,7 @@ public class JtaTransactionManager extends AbstractPlatformTransactionManager /** * Return the JTA TransactionManager that this transaction manager uses, if any. */ + @Nullable public TransactionManager getTransactionManager() { return this.transactionManager; } @@ -383,6 +386,7 @@ public class JtaTransactionManager extends AbstractPlatformTransactionManager /** * Return the JTA 1.1 TransactionSynchronizationRegistry that this transaction manager uses, if any. */ + @Nullable public TransactionSynchronizationRegistry getTransactionSynchronizationRegistry() { return this.transactionSynchronizationRegistry; } @@ -632,6 +636,7 @@ public class JtaTransactionManager extends AbstractPlatformTransactionManager * @see #setUserTransaction * @see #setUserTransactionName */ + @Nullable protected UserTransaction retrieveUserTransaction() throws TransactionSystemException { return null; } @@ -645,6 +650,7 @@ public class JtaTransactionManager extends AbstractPlatformTransactionManager * @see #setTransactionManager * @see #setTransactionManagerName */ + @Nullable protected TransactionManager retrieveTransactionManager() throws TransactionSystemException { return null; } @@ -657,6 +663,7 @@ public class JtaTransactionManager extends AbstractPlatformTransactionManager * or {@code null} if none found * @throws TransactionSystemException in case of errors */ + @Nullable protected TransactionSynchronizationRegistry retrieveTransactionSynchronizationRegistry() throws TransactionSystemException { return null; } @@ -667,6 +674,7 @@ public class JtaTransactionManager extends AbstractPlatformTransactionManager * @return the JTA UserTransaction reference, or {@code null} if not found * @see #DEFAULT_USER_TRANSACTION_NAME */ + @Nullable protected UserTransaction findUserTransaction() { String jndiName = DEFAULT_USER_TRANSACTION_NAME; try { @@ -693,6 +701,7 @@ public class JtaTransactionManager extends AbstractPlatformTransactionManager * @return the JTA TransactionManager reference, or {@code null} if not found * @see #FALLBACK_TRANSACTION_MANAGER_NAMES */ + @Nullable protected TransactionManager findTransactionManager(UserTransaction ut) { if (ut instanceof TransactionManager) { if (logger.isDebugEnabled()) { @@ -732,6 +741,7 @@ public class JtaTransactionManager extends AbstractPlatformTransactionManager * or {@code null} if none found * @throws TransactionSystemException in case of errors */ + @Nullable protected TransactionSynchronizationRegistry findTransactionSynchronizationRegistry(UserTransaction ut, TransactionManager tm) throws TransactionSystemException { diff --git a/spring-tx/src/main/java/org/springframework/transaction/jta/TransactionFactory.java b/spring-tx/src/main/java/org/springframework/transaction/jta/TransactionFactory.java index aac7f91e5e..d2b14df097 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/jta/TransactionFactory.java +++ b/spring-tx/src/main/java/org/springframework/transaction/jta/TransactionFactory.java @@ -20,6 +20,8 @@ import javax.transaction.NotSupportedException; import javax.transaction.SystemException; import javax.transaction.Transaction; +import org.springframework.lang.Nullable; + /** * Strategy interface for creating JTA {@link javax.transaction.Transaction} * objects based on specified transactional characteristics. @@ -47,7 +49,7 @@ public interface TransactionFactory { * @throws SystemException if the transaction manager failed to create the * transaction */ - Transaction createTransaction(String name, int timeout) throws NotSupportedException, SystemException; + Transaction createTransaction(@Nullable String name, int timeout) throws NotSupportedException, SystemException; /** * Determine whether the underlying transaction manager supports XA transactions diff --git a/spring-tx/src/main/java/org/springframework/transaction/jta/package-info.java b/spring-tx/src/main/java/org/springframework/transaction/jta/package-info.java index 10a3800499..457655376f 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/jta/package-info.java +++ b/spring-tx/src/main/java/org/springframework/transaction/jta/package-info.java @@ -1,4 +1,7 @@ /** * Transaction SPI implementation for JTA. */ +@NonNullApi package org.springframework.transaction.jta; + +import org.springframework.lang.NonNullApi; diff --git a/spring-tx/src/main/java/org/springframework/transaction/package-info.java b/spring-tx/src/main/java/org/springframework/transaction/package-info.java index d28c7a7e5d..c8303416d4 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/package-info.java +++ b/spring-tx/src/main/java/org/springframework/transaction/package-info.java @@ -3,4 +3,7 @@ * independent of any specific transaction management system. * Contains transaction manager, definition, and status interfaces. */ +@NonNullApi package org.springframework.transaction; + +import org.springframework.lang.NonNullApi; diff --git a/spring-tx/src/main/java/org/springframework/transaction/support/AbstractPlatformTransactionManager.java b/spring-tx/src/main/java/org/springframework/transaction/support/AbstractPlatformTransactionManager.java index ce23664ba1..8448fb6491 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/support/AbstractPlatformTransactionManager.java +++ b/spring-tx/src/main/java/org/springframework/transaction/support/AbstractPlatformTransactionManager.java @@ -25,6 +25,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.core.Constants; +import org.springframework.lang.Nullable; import org.springframework.transaction.IllegalTransactionStateException; import org.springframework.transaction.InvalidTimeoutException; import org.springframework.transaction.NestedTransactionNotSupportedException; @@ -562,7 +563,8 @@ public abstract class AbstractPlatformTransactionManager implements PlatformTran * @see #doSuspend * @see #resume */ - protected final SuspendedResourcesHolder suspend(Object transaction) throws TransactionException { + @Nullable + protected final SuspendedResourcesHolder suspend(@Nullable Object transaction) throws TransactionException { if (TransactionSynchronizationManager.isSynchronizationActive()) { List suspendedSynchronizations = doSuspendSynchronization(); try { @@ -608,7 +610,7 @@ public abstract class AbstractPlatformTransactionManager implements PlatformTran * @see #doResume * @see #suspend */ - protected final void resume(Object transaction, SuspendedResourcesHolder resourcesHolder) + protected final void resume(Object transaction, @Nullable SuspendedResourcesHolder resourcesHolder) throws TransactionException { if (resourcesHolder != null) { diff --git a/spring-tx/src/main/java/org/springframework/transaction/support/AbstractTransactionStatus.java b/spring-tx/src/main/java/org/springframework/transaction/support/AbstractTransactionStatus.java index 1cfcda34cd..7c15a7e0db 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/support/AbstractTransactionStatus.java +++ b/spring-tx/src/main/java/org/springframework/transaction/support/AbstractTransactionStatus.java @@ -16,6 +16,7 @@ package org.springframework.transaction.support; +import org.springframework.lang.Nullable; import org.springframework.transaction.NestedTransactionNotSupportedException; import org.springframework.transaction.SavepointManager; import org.springframework.transaction.TransactionException; @@ -126,6 +127,7 @@ public abstract class AbstractTransactionStatus implements TransactionStatus { /** * Get the savepoint for this transaction, if any. */ + @Nullable protected Object getSavepoint() { return this.savepoint; } diff --git a/spring-tx/src/main/java/org/springframework/transaction/support/CallbackPreferringPlatformTransactionManager.java b/spring-tx/src/main/java/org/springframework/transaction/support/CallbackPreferringPlatformTransactionManager.java index 6a1f9decf0..c6503577be 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/support/CallbackPreferringPlatformTransactionManager.java +++ b/spring-tx/src/main/java/org/springframework/transaction/support/CallbackPreferringPlatformTransactionManager.java @@ -16,6 +16,7 @@ package org.springframework.transaction.support; +import org.springframework.lang.Nullable; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.TransactionDefinition; import org.springframework.transaction.TransactionException; @@ -53,6 +54,7 @@ public interface CallbackPreferringPlatformTransactionManager extends PlatformTr * @throws TransactionException in case of initialization, rollback, or system errors * @throws RuntimeException if thrown by the TransactionCallback */ + @Nullable T execute(TransactionDefinition definition, TransactionCallback callback) throws TransactionException; diff --git a/spring-tx/src/main/java/org/springframework/transaction/support/DefaultTransactionStatus.java b/spring-tx/src/main/java/org/springframework/transaction/support/DefaultTransactionStatus.java index 22f6f46acc..ab0bd64eb1 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/support/DefaultTransactionStatus.java +++ b/spring-tx/src/main/java/org/springframework/transaction/support/DefaultTransactionStatus.java @@ -16,6 +16,7 @@ package org.springframework.transaction.support; +import org.springframework.lang.Nullable; import org.springframework.transaction.NestedTransactionNotSupportedException; import org.springframework.transaction.SavepointManager; @@ -78,7 +79,7 @@ public class DefaultTransactionStatus extends AbstractTransactionStatus { */ public DefaultTransactionStatus( Object transaction, boolean newTransaction, boolean newSynchronization, - boolean readOnly, boolean debug, Object suspendedResources) { + boolean readOnly, boolean debug, @Nullable Object suspendedResources) { this.transaction = transaction; this.newTransaction = newTransaction; @@ -136,6 +137,7 @@ public class DefaultTransactionStatus extends AbstractTransactionStatus { * Return the holder for resources that have been suspended for this transaction, * if any. */ + @Nullable public Object getSuspendedResources() { return this.suspendedResources; } diff --git a/spring-tx/src/main/java/org/springframework/transaction/support/TransactionCallback.java b/spring-tx/src/main/java/org/springframework/transaction/support/TransactionCallback.java index 8e298d0081..6e3ac2d64b 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/support/TransactionCallback.java +++ b/spring-tx/src/main/java/org/springframework/transaction/support/TransactionCallback.java @@ -16,6 +16,7 @@ package org.springframework.transaction.support; +import org.springframework.lang.Nullable; import org.springframework.transaction.TransactionStatus; /** @@ -50,6 +51,7 @@ public interface TransactionCallback { * @see TransactionTemplate#execute * @see CallbackPreferringPlatformTransactionManager#execute */ + @Nullable T doInTransaction(TransactionStatus status); } diff --git a/spring-tx/src/main/java/org/springframework/transaction/support/TransactionOperations.java b/spring-tx/src/main/java/org/springframework/transaction/support/TransactionOperations.java index bc1ffbc820..51e62169f4 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/support/TransactionOperations.java +++ b/spring-tx/src/main/java/org/springframework/transaction/support/TransactionOperations.java @@ -16,6 +16,7 @@ package org.springframework.transaction.support; +import org.springframework.lang.Nullable; import org.springframework.transaction.TransactionException; /** @@ -40,6 +41,7 @@ public interface TransactionOperations { * @throws TransactionException in case of initialization, rollback, or system errors * @throws RuntimeException if thrown by the TransactionCallback */ + @Nullable T execute(TransactionCallback action) throws TransactionException; } diff --git a/spring-tx/src/main/java/org/springframework/transaction/support/TransactionSynchronizationManager.java b/spring-tx/src/main/java/org/springframework/transaction/support/TransactionSynchronizationManager.java index e3885bd6ec..db948e05c4 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/support/TransactionSynchronizationManager.java +++ b/spring-tx/src/main/java/org/springframework/transaction/support/TransactionSynchronizationManager.java @@ -29,6 +29,7 @@ import org.apache.commons.logging.LogFactory; import org.springframework.core.NamedThreadLocal; import org.springframework.core.annotation.AnnotationAwareOrderComparator; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -133,6 +134,7 @@ public abstract class TransactionSynchronizationManager { * resource object), or {@code null} if none * @see ResourceTransactionManager#getResourceFactory() */ + @Nullable public static Object getResource(Object key) { Object actualKey = TransactionSynchronizationUtils.unwrapResourceIfNecessary(key); Object value = doGetResource(actualKey); @@ -146,6 +148,7 @@ public abstract class TransactionSynchronizationManager { /** * Actually check the value of the resource that is bound for the given key. */ + @Nullable private static Object doGetResource(Object actualKey) { Map map = resources.get(); if (map == null) { @@ -217,6 +220,7 @@ public abstract class TransactionSynchronizationManager { * @param key the key to unbind (usually the resource factory) * @return the previously bound value, or {@code null} if none bound */ + @Nullable public static Object unbindResourceIfPossible(Object key) { Object actualKey = TransactionSynchronizationUtils.unwrapResourceIfNecessary(key); return doUnbindResource(actualKey); @@ -225,6 +229,7 @@ public abstract class TransactionSynchronizationManager { /** * Actually remove the value of the resource that is bound for the given key. */ + @Nullable private static Object doUnbindResource(Object actualKey) { Map map = resources.get(); if (map == null) { @@ -343,7 +348,7 @@ public abstract class TransactionSynchronizationManager { * @param name the name of the transaction, or {@code null} to reset it * @see org.springframework.transaction.TransactionDefinition#getName() */ - public static void setCurrentTransactionName(String name) { + public static void setCurrentTransactionName(@Nullable String name) { currentTransactionName.set(name); } @@ -353,6 +358,7 @@ public abstract class TransactionSynchronizationManager { * for example to optimize fetch strategies for specific named transactions. * @see org.springframework.transaction.TransactionDefinition#getName() */ + @Nullable public static String getCurrentTransactionName() { return currentTransactionName.get(); } @@ -400,7 +406,7 @@ public abstract class TransactionSynchronizationManager { * @see org.springframework.transaction.TransactionDefinition#ISOLATION_SERIALIZABLE * @see org.springframework.transaction.TransactionDefinition#getIsolationLevel() */ - public static void setCurrentTransactionIsolationLevel(Integer isolationLevel) { + public static void setCurrentTransactionIsolationLevel(@Nullable Integer isolationLevel) { currentTransactionIsolationLevel.set(isolationLevel); } @@ -421,6 +427,7 @@ public abstract class TransactionSynchronizationManager { * @see org.springframework.transaction.TransactionDefinition#ISOLATION_SERIALIZABLE * @see org.springframework.transaction.TransactionDefinition#getIsolationLevel() */ + @Nullable public static Integer getCurrentTransactionIsolationLevel() { return currentTransactionIsolationLevel.get(); } diff --git a/spring-tx/src/main/java/org/springframework/transaction/support/package-info.java b/spring-tx/src/main/java/org/springframework/transaction/support/package-info.java index a7d4b63107..7a6d172a4f 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/support/package-info.java +++ b/spring-tx/src/main/java/org/springframework/transaction/support/package-info.java @@ -3,4 +3,7 @@ * Provides an abstract base class for transaction manager implementations, * and a template plus callback for transaction demarcation. */ +@NonNullApi package org.springframework.transaction.support; + +import org.springframework.lang.NonNullApi; diff --git a/spring-web/src/main/java/org/springframework/http/CacheControl.java b/spring-web/src/main/java/org/springframework/http/CacheControl.java index c99333445f..2e8ce692f8 100644 --- a/spring-web/src/main/java/org/springframework/http/CacheControl.java +++ b/spring-web/src/main/java/org/springframework/http/CacheControl.java @@ -18,6 +18,7 @@ package org.springframework.http; import java.util.concurrent.TimeUnit; +import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; /** @@ -246,6 +247,7 @@ public class CacheControl { * Return the "Cache-Control" header value. * @return {@code null} if no directive was added, or the header value otherwise */ + @Nullable public String getHeaderValue() { StringBuilder ccValue = new StringBuilder(); if (this.maxAge != -1) { diff --git a/spring-web/src/main/java/org/springframework/http/ContentDisposition.java b/spring-web/src/main/java/org/springframework/http/ContentDisposition.java index a2dd5baece..163d258dc8 100644 --- a/spring-web/src/main/java/org/springframework/http/ContentDisposition.java +++ b/spring-web/src/main/java/org/springframework/http/ContentDisposition.java @@ -20,6 +20,7 @@ import java.io.ByteArrayOutputStream; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -61,6 +62,7 @@ public class ContentDisposition { * Return the disposition type, like for example {@literal inline}, {@literal attachment}, * {@literal form-data}, or {@code null} if not defined. */ + @Nullable public String getType() { return this.type; } @@ -68,6 +70,7 @@ public class ContentDisposition { /** * Return the value of the {@literal name} parameter, or {@code null} if not defined. */ + @Nullable public String getName() { return this.name; } @@ -76,6 +79,7 @@ public class ContentDisposition { * Return the value of the {@literal filename} parameter (or the value of the * {@literal filename*} one decoded as defined in the RFC 5987), or {@code null} if not defined. */ + @Nullable public String getFilename() { return this.filename; } @@ -83,6 +87,7 @@ public class ContentDisposition { /** * Return the charset defined in {@literal filename*} parameter, or {@code null} if not defined. */ + @Nullable public Charset getCharset() { return this.charset; } @@ -90,6 +95,7 @@ public class ContentDisposition { /** * Return the value of the {@literal size} parameter, or {@code null} if not defined. */ + @Nullable public Long getSize() { return this.size; } diff --git a/spring-web/src/main/java/org/springframework/http/HttpHeaders.java b/spring-web/src/main/java/org/springframework/http/HttpHeaders.java index c3ce739265..a8833f354f 100644 --- a/spring-web/src/main/java/org/springframework/http/HttpHeaders.java +++ b/spring-web/src/main/java/org/springframework/http/HttpHeaders.java @@ -41,6 +41,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.LinkedCaseInsensitiveMap; import org.springframework.util.MultiValueMap; @@ -740,7 +741,7 @@ public class HttpHeaders implements MultiValueMap, Serializable * @see #setContentDisposition(ContentDisposition) * @see #getContentDisposition() */ - public void setContentDispositionFormData(String name, String filename) { + public void setContentDispositionFormData(String name, @Nullable String filename) { setContentDispositionFormData(name, filename, null); } @@ -756,7 +757,7 @@ public class HttpHeaders implements MultiValueMap, Serializable * @see #getContentDisposition() * @see RFC 7230 Section 3.2.4 */ - public void setContentDispositionFormData(String name, String filename, Charset charset) { + public void setContentDispositionFormData(String name, @Nullable String filename, @Nullable Charset charset) { Assert.notNull(name, "'name' must not be null"); ContentDisposition disposition = ContentDisposition.builder("form-data") .name(name).filename(filename, charset).build(); @@ -811,6 +812,7 @@ public class HttpHeaders implements MultiValueMap, Serializable * to get multiple content languages.

    * @since 5.0 */ + @Nullable public Locale getContentLanguage() { return getValuesAsList(CONTENT_LANGUAGE) .stream() @@ -852,6 +854,7 @@ public class HttpHeaders implements MultiValueMap, Serializable * by the {@code Content-Type} header. *

    Returns {@code null} when the content-type is unknown. */ + @Nullable public MediaType getContentType() { String value = getFirst(CONTENT_TYPE); return (StringUtils.hasLength(value) ? MediaType.parseMediaType(value) : null); @@ -936,6 +939,7 @@ public class HttpHeaders implements MultiValueMap, Serializable * {@linkplain InetSocketAddress#getPort() port} will be {@code 0}. * @since 5.0 */ + @Nullable public InetSocketAddress getHost() { String value = getFirst(HOST); if (value == null) { @@ -1076,6 +1080,7 @@ public class HttpHeaders implements MultiValueMap, Serializable * as specified by the {@code Location} header. *

    Returns {@code null} when the location is unknown. */ + @Nullable public URI getLocation() { String value = getFirst(LOCATION); return (value != null ? URI.create(value) : null); diff --git a/spring-web/src/main/java/org/springframework/http/HttpMethod.java b/spring-web/src/main/java/org/springframework/http/HttpMethod.java index 3a21183632..62d7ffe36a 100644 --- a/spring-web/src/main/java/org/springframework/http/HttpMethod.java +++ b/spring-web/src/main/java/org/springframework/http/HttpMethod.java @@ -19,6 +19,8 @@ package org.springframework.http; import java.util.HashMap; import java.util.Map; +import org.springframework.lang.Nullable; + /** * Java 5 enumeration of HTTP request methods. Intended for use * with {@link org.springframework.http.client.ClientHttpRequest} @@ -48,6 +50,7 @@ public enum HttpMethod { * @return the corresponding {@code HttpMethod}, or {@code null} if not found * @since 4.2.4 */ + @Nullable public static HttpMethod resolve(String method) { return (method != null ? mappings.get(method) : null); } diff --git a/spring-web/src/main/java/org/springframework/http/HttpRequest.java b/spring-web/src/main/java/org/springframework/http/HttpRequest.java index ad5bc9b733..627982c4ed 100644 --- a/spring-web/src/main/java/org/springframework/http/HttpRequest.java +++ b/spring-web/src/main/java/org/springframework/http/HttpRequest.java @@ -18,6 +18,8 @@ package org.springframework.http; import java.net.URI; +import org.springframework.lang.Nullable; + /** * Represents an HTTP request message, consisting of * {@linkplain #getMethod() method} and {@linkplain #getURI() uri}. @@ -32,6 +34,7 @@ public interface HttpRequest extends HttpMessage { * @return the HTTP method as an HttpMethod enum value, or {@code null} * if not resolvable (e.g. in case of a non-standard HTTP method) */ + @Nullable default HttpMethod getMethod() { return HttpMethod.resolve(getMethodValue()); } diff --git a/spring-web/src/main/java/org/springframework/http/MediaType.java b/spring-web/src/main/java/org/springframework/http/MediaType.java index 821e84bb22..a5564d5128 100644 --- a/spring-web/src/main/java/org/springframework/http/MediaType.java +++ b/spring-web/src/main/java/org/springframework/http/MediaType.java @@ -27,6 +27,7 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.util.InvalidMimeTypeException; @@ -380,7 +381,7 @@ public class MediaType extends MimeType implements Serializable { * @param parameters the parameters, may be {@code null} * @throws IllegalArgumentException if any of the parameters contain illegal characters */ - public MediaType(MediaType other, Map parameters) { + public MediaType(MediaType other, @Nullable Map parameters) { super(other.getType(), other.getSubtype(), parameters); } @@ -391,7 +392,7 @@ public class MediaType extends MimeType implements Serializable { * @param parameters the parameters, may be {@code null} * @throws IllegalArgumentException if any of the parameters contain illegal characters */ - public MediaType(String type, String subtype, Map parameters) { + public MediaType(String type, String subtype, @Nullable Map parameters) { super(type, subtype, parameters); } diff --git a/spring-web/src/main/java/org/springframework/http/MediaTypeFactory.java b/spring-web/src/main/java/org/springframework/http/MediaTypeFactory.java index b5ecdd59f7..8cfb899a41 100644 --- a/spring-web/src/main/java/org/springframework/http/MediaTypeFactory.java +++ b/spring-web/src/main/java/org/springframework/http/MediaTypeFactory.java @@ -27,6 +27,7 @@ import java.util.Locale; import java.util.Optional; import org.springframework.core.io.Resource; +import org.springframework.lang.Nullable; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.util.StringUtils; @@ -97,7 +98,7 @@ public class MediaTypeFactory { * @param resource the resource to introspect * @return the corresponding media type, or {@code null} if none found */ - public static Optional getMediaType(Resource resource) { + public static Optional getMediaType(@Nullable Resource resource) { return Optional.ofNullable(resource) .map(Resource::getFilename) .flatMap(MediaTypeFactory::getMediaType); @@ -108,7 +109,7 @@ public class MediaTypeFactory { * @param filename the file name plus extension * @return the corresponding media type, or {@code null} if none found */ - public static Optional getMediaType(String filename) { + public static Optional getMediaType(@Nullable String filename) { return getMediaTypes(filename).stream().findFirst(); } @@ -117,7 +118,7 @@ public class MediaTypeFactory { * @param filename the file name plus extension * @return the corresponding media types, or an empty list if none found */ - public static List getMediaTypes(String filename) { + public static List getMediaTypes(@Nullable String filename) { return Optional.ofNullable(StringUtils.getFilenameExtension(filename)) .map(s -> s.toLowerCase(Locale.ENGLISH)) .map(fileExtensionToMediaTypes::get) diff --git a/spring-web/src/main/java/org/springframework/http/RequestEntity.java b/spring-web/src/main/java/org/springframework/http/RequestEntity.java index cf7a0b95b5..09b5b795dd 100644 --- a/spring-web/src/main/java/org/springframework/http/RequestEntity.java +++ b/spring-web/src/main/java/org/springframework/http/RequestEntity.java @@ -21,6 +21,7 @@ import java.net.URI; import java.nio.charset.Charset; import java.util.Arrays; +import org.springframework.lang.Nullable; import org.springframework.util.MultiValueMap; import org.springframework.util.ObjectUtils; @@ -159,6 +160,7 @@ public class RequestEntity extends HttpEntity { * @return the request's body type, or {@code null} if not known * @since 4.3 */ + @Nullable public Type getType() { if (this.type == null) { T body = getBody(); diff --git a/spring-web/src/main/java/org/springframework/http/ResponseCookie.java b/spring-web/src/main/java/org/springframework/http/ResponseCookie.java index 1a8f37798c..46c62c16c5 100644 --- a/spring-web/src/main/java/org/springframework/http/ResponseCookie.java +++ b/spring-web/src/main/java/org/springframework/http/ResponseCookie.java @@ -18,6 +18,7 @@ package org.springframework.http; import java.time.Duration; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; @@ -73,6 +74,7 @@ public final class ResponseCookie extends HttpCookie { /** * Return the cookie "Domain" attribute, or {@code null} if not set. */ + @Nullable public String getDomain() { return this.domain; } @@ -80,6 +82,7 @@ public final class ResponseCookie extends HttpCookie { /** * Return the cookie "Path" attribute, or {@code null} if not set. */ + @Nullable public String getPath() { return this.path; } diff --git a/spring-web/src/main/java/org/springframework/http/client/HttpComponentsClientHttpRequestFactory.java b/spring-web/src/main/java/org/springframework/http/client/HttpComponentsClientHttpRequestFactory.java index fdfd45163f..9aed5b5051 100644 --- a/spring-web/src/main/java/org/springframework/http/client/HttpComponentsClientHttpRequestFactory.java +++ b/spring-web/src/main/java/org/springframework/http/client/HttpComponentsClientHttpRequestFactory.java @@ -38,6 +38,7 @@ import org.apache.http.protocol.HttpContext; import org.springframework.beans.factory.DisposableBean; import org.springframework.http.HttpMethod; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -204,6 +205,7 @@ public class HttpComponentsClientHttpRequestFactory implements ClientHttpRequest * @since 4.2 * @see #mergeRequestConfig(RequestConfig) */ + @Nullable protected RequestConfig createRequestConfig(Object client) { if (client instanceof Configurable) { RequestConfig clientRequestConfig = ((Configurable) client).getConfig(); @@ -220,7 +222,8 @@ public class HttpComponentsClientHttpRequestFactory implements ClientHttpRequest * (may be {@code null} if the given client config is {@code null}) * @since 4.2 */ - protected RequestConfig mergeRequestConfig(RequestConfig clientConfig) { + @Nullable + protected RequestConfig mergeRequestConfig(@Nullable RequestConfig clientConfig) { if (this.requestConfig == null) { // nothing to merge return clientConfig; } @@ -286,6 +289,7 @@ public class HttpComponentsClientHttpRequestFactory implements ClientHttpRequest * @param uri the URI * @return the http context */ + @Nullable protected HttpContext createHttpContext(HttpMethod httpMethod, URI uri) { return null; } diff --git a/spring-web/src/main/java/org/springframework/http/client/InterceptingClientHttpRequestFactory.java b/spring-web/src/main/java/org/springframework/http/client/InterceptingClientHttpRequestFactory.java index e23190c8b8..6585700961 100644 --- a/spring-web/src/main/java/org/springframework/http/client/InterceptingClientHttpRequestFactory.java +++ b/spring-web/src/main/java/org/springframework/http/client/InterceptingClientHttpRequestFactory.java @@ -21,6 +21,7 @@ import java.util.Collections; import java.util.List; import org.springframework.http.HttpMethod; +import org.springframework.lang.Nullable; /** * {@link ClientHttpRequestFactory} wrapper with support for {@link ClientHttpRequestInterceptor}s. @@ -41,7 +42,7 @@ public class InterceptingClientHttpRequestFactory extends AbstractClientHttpRequ * @param interceptors the interceptors that are to be applied (can be {@code null}) */ public InterceptingClientHttpRequestFactory(ClientHttpRequestFactory requestFactory, - List interceptors) { + @Nullable List interceptors) { super(requestFactory); this.interceptors = (interceptors != null ? interceptors : Collections.emptyList()); diff --git a/spring-web/src/main/java/org/springframework/http/client/SimpleClientHttpRequestFactory.java b/spring-web/src/main/java/org/springframework/http/client/SimpleClientHttpRequestFactory.java index 17bcd6c1d4..ab821d58f9 100644 --- a/spring-web/src/main/java/org/springframework/http/client/SimpleClientHttpRequestFactory.java +++ b/spring-web/src/main/java/org/springframework/http/client/SimpleClientHttpRequestFactory.java @@ -25,6 +25,7 @@ import java.net.URLConnection; import org.springframework.core.task.AsyncListenableTaskExecutor; import org.springframework.http.HttpMethod; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -180,7 +181,7 @@ public class SimpleClientHttpRequestFactory implements ClientHttpRequestFactory, * @return the opened connection * @throws IOException in case of I/O errors */ - protected HttpURLConnection openConnection(URL url, Proxy proxy) throws IOException { + protected HttpURLConnection openConnection(URL url, @Nullable Proxy proxy) throws IOException { URLConnection urlConnection = (proxy != null ? url.openConnection(proxy) : url.openConnection()); if (!HttpURLConnection.class.isInstance(urlConnection)) { throw new IllegalStateException("HttpURLConnection required for [" + url + "] but got: " + urlConnection); diff --git a/spring-web/src/main/java/org/springframework/http/client/package-info.java b/spring-web/src/main/java/org/springframework/http/client/package-info.java index c0e1c676ec..ce85f7f341 100644 --- a/spring-web/src/main/java/org/springframework/http/client/package-info.java +++ b/spring-web/src/main/java/org/springframework/http/client/package-info.java @@ -3,4 +3,7 @@ * contains the {@code ClientHttpRequest} and {@code ClientHttpResponse}, * as well as a basic implementation of these interfaces. */ +@NonNullApi package org.springframework.http.client; + +import org.springframework.lang.NonNullApi; diff --git a/spring-web/src/main/java/org/springframework/http/client/reactive/AbstractClientHttpRequest.java b/spring-web/src/main/java/org/springframework/http/client/reactive/AbstractClientHttpRequest.java index 88d480c6b0..d2ab80aec7 100644 --- a/spring-web/src/main/java/org/springframework/http/client/reactive/AbstractClientHttpRequest.java +++ b/spring-web/src/main/java/org/springframework/http/client/reactive/AbstractClientHttpRequest.java @@ -27,6 +27,7 @@ import reactor.core.publisher.Mono; import org.springframework.http.HttpCookie; import org.springframework.http.HttpHeaders; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.util.LinkedMultiValueMap; @@ -111,7 +112,7 @@ public abstract class AbstractClientHttpRequest implements ClientHttpRequest { * @param writeAction the action to write the request body (may be {@code null}) * @return a completion publisher */ - protected Mono doCommit(Supplier> writeAction) { + protected Mono doCommit(@Nullable Supplier> writeAction) { if (!this.state.compareAndSet(State.NEW, State.COMMITTING)) { return Mono.empty(); } diff --git a/spring-web/src/main/java/org/springframework/http/client/reactive/package-info.java b/spring-web/src/main/java/org/springframework/http/client/reactive/package-info.java index 79d1989b50..57af2c3cee 100644 --- a/spring-web/src/main/java/org/springframework/http/client/reactive/package-info.java +++ b/spring-web/src/main/java/org/springframework/http/client/reactive/package-info.java @@ -4,4 +4,7 @@ * {@link org.springframework.http.client.reactive.ClientHttpResponse} as well as a * {@link org.springframework.http.client.reactive.ClientHttpConnector}. */ +@NonNullApi package org.springframework.http.client.reactive; + +import org.springframework.lang.NonNullApi; diff --git a/spring-web/src/main/java/org/springframework/http/client/support/package-info.java b/spring-web/src/main/java/org/springframework/http/client/support/package-info.java index 97f55aa1c2..eb74fbcb03 100644 --- a/spring-web/src/main/java/org/springframework/http/client/support/package-info.java +++ b/spring-web/src/main/java/org/springframework/http/client/support/package-info.java @@ -2,4 +2,7 @@ * This package provides generic HTTP support classes, * to be used by higher-level classes like RestTemplate. */ +@NonNullApi package org.springframework.http.client.support; + +import org.springframework.lang.NonNullApi; diff --git a/spring-web/src/main/java/org/springframework/http/codec/HttpMessageReader.java b/spring-web/src/main/java/org/springframework/http/codec/HttpMessageReader.java index c087de0bf0..f44b960974 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/HttpMessageReader.java +++ b/spring-web/src/main/java/org/springframework/http/codec/HttpMessageReader.java @@ -28,6 +28,7 @@ import org.springframework.http.MediaType; import org.springframework.http.ReactiveHttpInputMessage; import org.springframework.http.server.reactive.ServerHttpRequest; import org.springframework.http.server.reactive.ServerHttpResponse; +import org.springframework.lang.Nullable; /** * Strategy for reading from a {@link ReactiveHttpInputMessage} and decoding @@ -53,7 +54,7 @@ public interface HttpMessageReader { * @param mediaType the media type for the read, possibly {@code null} * @return {@code true} if readable, {@code false} otherwise */ - boolean canRead(ResolvableType elementType, MediaType mediaType); + boolean canRead(ResolvableType elementType, @Nullable MediaType mediaType); /** * Read from the input message and encode to a stream of objects. diff --git a/spring-web/src/main/java/org/springframework/http/codec/HttpMessageWriter.java b/spring-web/src/main/java/org/springframework/http/codec/HttpMessageWriter.java index 1a04e91136..86bfb30724 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/HttpMessageWriter.java +++ b/spring-web/src/main/java/org/springframework/http/codec/HttpMessageWriter.java @@ -28,6 +28,7 @@ import org.springframework.http.MediaType; import org.springframework.http.ReactiveHttpOutputMessage; import org.springframework.http.server.reactive.ServerHttpRequest; import org.springframework.http.server.reactive.ServerHttpResponse; +import org.springframework.lang.Nullable; /** * Strategy for encoding a stream of objects of type {@code } and writing @@ -67,7 +68,7 @@ public interface HttpMessageWriter { * @return indicates completion or error */ Mono write(Publisher inputStream, ResolvableType elementType, - MediaType mediaType, ReactiveHttpOutputMessage message, Map hints); + @Nullable MediaType mediaType, ReactiveHttpOutputMessage message, Map hints); /** * Server-side only alternative to @@ -85,7 +86,7 @@ public interface HttpMessageWriter { * @return a {@link Mono} that indicates completion of writing or error */ default Mono write(Publisher inputStream, ResolvableType actualType, - ResolvableType elementType, MediaType mediaType, ServerHttpRequest request, + ResolvableType elementType, @Nullable MediaType mediaType, ServerHttpRequest request, ServerHttpResponse response, Map hints) { return write(inputStream, elementType, mediaType, response, hints); diff --git a/spring-web/src/main/java/org/springframework/http/codec/ServerSentEvent.java b/spring-web/src/main/java/org/springframework/http/codec/ServerSentEvent.java index da9f4a1738..ade2a40575 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/ServerSentEvent.java +++ b/spring-web/src/main/java/org/springframework/http/codec/ServerSentEvent.java @@ -19,6 +19,7 @@ package org.springframework.http.codec; import java.time.Duration; import org.springframework.http.codec.json.Jackson2JsonEncoder; +import org.springframework.lang.Nullable; /** * Representation for a Server-Sent Event for use with Spring's reactive Web support. @@ -58,6 +59,7 @@ public class ServerSentEvent { /** * Return the {@code id} field of this event, if available. */ + @Nullable public String id() { return this.id; } @@ -65,6 +67,7 @@ public class ServerSentEvent { /** * Return the {@code event} field of this event, if available. */ + @Nullable public String event() { return this.event; } @@ -72,6 +75,7 @@ public class ServerSentEvent { /** * Return the {@code data} field of this event, if available. */ + @Nullable public T data() { return this.data; } @@ -79,6 +83,7 @@ public class ServerSentEvent { /** * Return the {@code retry} field of this event, if available. */ + @Nullable public Duration retry() { return this.retry; } @@ -86,6 +91,7 @@ public class ServerSentEvent { /** * Return the comment of this event, if available. */ + @Nullable public String comment() { return this.comment; } diff --git a/spring-web/src/main/java/org/springframework/http/codec/ServerSentEventHttpMessageWriter.java b/spring-web/src/main/java/org/springframework/http/codec/ServerSentEventHttpMessageWriter.java index a6859ccc98..c0631d6e46 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/ServerSentEventHttpMessageWriter.java +++ b/spring-web/src/main/java/org/springframework/http/codec/ServerSentEventHttpMessageWriter.java @@ -35,6 +35,7 @@ import org.springframework.http.MediaType; import org.springframework.http.ReactiveHttpOutputMessage; import org.springframework.http.server.reactive.ServerHttpRequest; import org.springframework.http.server.reactive.ServerHttpResponse; +import org.springframework.lang.Nullable; /** * {@code HttpMessageWriter} for {@code "text/event-stream"} responses. @@ -74,6 +75,7 @@ public class ServerSentEventHttpMessageWriter implements HttpMessageWriter getEncoder() { return this.encoder; } diff --git a/spring-web/src/main/java/org/springframework/http/codec/json/package-info.java b/spring-web/src/main/java/org/springframework/http/codec/json/package-info.java index 2336313778..5039cba406 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/json/package-info.java +++ b/spring-web/src/main/java/org/springframework/http/codec/json/package-info.java @@ -1,4 +1,7 @@ /** * JSON encoder and decoder support. */ +@NonNullApi package org.springframework.http.codec.json; + +import org.springframework.lang.NonNullApi; diff --git a/spring-web/src/main/java/org/springframework/http/codec/multipart/package-info.java b/spring-web/src/main/java/org/springframework/http/codec/multipart/package-info.java new file mode 100644 index 0000000000..c84c671122 --- /dev/null +++ b/spring-web/src/main/java/org/springframework/http/codec/multipart/package-info.java @@ -0,0 +1,7 @@ +/** + * Multipart support. + */ +@NonNullApi +package org.springframework.http.codec.multipart; + +import org.springframework.lang.NonNullApi; diff --git a/spring-web/src/main/java/org/springframework/http/codec/package-info.java b/spring-web/src/main/java/org/springframework/http/codec/package-info.java index 9670bcb49b..c52dbb555b 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/package-info.java +++ b/spring-web/src/main/java/org/springframework/http/codec/package-info.java @@ -7,4 +7,7 @@ * {@link org.springframework.http.codec.HttpMessageWriter} for reading and * writing the body of HTTP requests and responses. */ +@NonNullApi package org.springframework.http.codec; + +import org.springframework.lang.NonNullApi; diff --git a/spring-web/src/main/java/org/springframework/http/codec/xml/package-info.java b/spring-web/src/main/java/org/springframework/http/codec/xml/package-info.java index affc017940..28ac6bcd31 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/xml/package-info.java +++ b/spring-web/src/main/java/org/springframework/http/codec/xml/package-info.java @@ -1,4 +1,7 @@ /** * XML encoder and decoder support. */ +@NonNullApi package org.springframework.http.codec.xml; + +import org.springframework.lang.NonNullApi; diff --git a/spring-web/src/main/java/org/springframework/http/converter/AbstractGenericHttpMessageConverter.java b/spring-web/src/main/java/org/springframework/http/converter/AbstractGenericHttpMessageConverter.java index a15d0468d8..0fa8a44386 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/AbstractGenericHttpMessageConverter.java +++ b/spring-web/src/main/java/org/springframework/http/converter/AbstractGenericHttpMessageConverter.java @@ -24,6 +24,7 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.HttpOutputMessage; import org.springframework.http.MediaType; import org.springframework.http.StreamingHttpOutputMessage; +import org.springframework.lang.Nullable; /** * Abstract base class for most {@link GenericHttpMessageConverter} implementations. @@ -123,7 +124,7 @@ public abstract class AbstractGenericHttpMessageConverter extends AbstractHtt * @throws IOException in case of I/O errors * @throws HttpMessageNotWritableException in case of conversion errors */ - protected abstract void writeInternal(T t, Type type, HttpOutputMessage outputMessage) + protected abstract void writeInternal(T t, @Nullable Type type, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException; } diff --git a/spring-web/src/main/java/org/springframework/http/converter/AbstractHttpMessageConverter.java b/spring-web/src/main/java/org/springframework/http/converter/AbstractHttpMessageConverter.java index 1457cfea32..942365d462 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/AbstractHttpMessageConverter.java +++ b/spring-web/src/main/java/org/springframework/http/converter/AbstractHttpMessageConverter.java @@ -32,6 +32,7 @@ import org.springframework.http.HttpInputMessage; import org.springframework.http.HttpOutputMessage; import org.springframework.http.MediaType; import org.springframework.http.StreamingHttpOutputMessage; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -117,6 +118,7 @@ public abstract class AbstractHttpMessageConverter implements HttpMessageConv * Return the default character set, if any. * @since 4.3 */ + @Nullable public Charset getDefaultCharset() { return this.defaultCharset; } @@ -141,7 +143,7 @@ public abstract class AbstractHttpMessageConverter implements HttpMessageConv * @return {@code true} if the supported media types include the media type, * or if the media type is {@code null} */ - protected boolean canRead(MediaType mediaType) { + protected boolean canRead(@Nullable MediaType mediaType) { if (mediaType == null) { return true; } @@ -172,7 +174,7 @@ public abstract class AbstractHttpMessageConverter implements HttpMessageConv * @return {@code true} if the supported media types are compatible with the media type, * or if the media type is {@code null} */ - protected boolean canWrite(MediaType mediaType) { + protected boolean canWrite(@Nullable MediaType mediaType) { if (mediaType == null || MediaType.ALL.equals(mediaType)) { return true; } @@ -273,6 +275,7 @@ public abstract class AbstractHttpMessageConverter implements HttpMessageConv * @param t the type to return the content type for * @return the content type, or {@code null} if not known */ + @Nullable protected MediaType getDefaultContentType(T t) throws IOException { List mediaTypes = getSupportedMediaTypes(); return (!mediaTypes.isEmpty() ? mediaTypes.get(0) : null); @@ -285,7 +288,8 @@ public abstract class AbstractHttpMessageConverter implements HttpMessageConv * @param t the type to return the content length for * @return the content length, or {@code null} if not known */ - protected Long getContentLength(T t, MediaType contentType) throws IOException { + @Nullable + protected Long getContentLength(T t, @Nullable MediaType contentType) throws IOException { return null; } diff --git a/spring-web/src/main/java/org/springframework/http/converter/FormHttpMessageConverter.java b/spring-web/src/main/java/org/springframework/http/converter/FormHttpMessageConverter.java index c2463d5a7c..bba3aac8a1 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/FormHttpMessageConverter.java +++ b/spring-web/src/main/java/org/springframework/http/converter/FormHttpMessageConverter.java @@ -29,6 +29,7 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; + import javax.mail.internet.MimeUtility; import org.springframework.core.io.Resource; @@ -38,6 +39,7 @@ import org.springframework.http.HttpInputMessage; import org.springframework.http.HttpOutputMessage; import org.springframework.http.MediaType; import org.springframework.http.StreamingHttpOutputMessage; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MimeTypeUtils; @@ -431,6 +433,7 @@ public class FormHttpMessageConverter implements HttpMessageConverter extends HttpMessageConverter * Typically the value of a {@code Content-Type} header. * @return {@code true} if readable; {@code false} otherwise */ - boolean canRead(Type type, Class contextClass, MediaType mediaType); + boolean canRead(Type type, @Nullable Class contextClass, @Nullable MediaType mediaType); /** * Read an object of the given type form the given input message, and returns it. @@ -62,7 +63,7 @@ public interface GenericHttpMessageConverter extends HttpMessageConverter * @throws IOException in case of I/O errors * @throws HttpMessageNotReadableException in case of conversion errors */ - T read(Type type, Class contextClass, HttpInputMessage inputMessage) + T read(Type type, @Nullable Class contextClass, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException; /** @@ -78,7 +79,7 @@ public interface GenericHttpMessageConverter extends HttpMessageConverter * @return {@code true} if writable; {@code false} otherwise * @since 4.2 */ - boolean canWrite(Type type, Class clazz, MediaType mediaType); + boolean canWrite(@Nullable Type type, Class clazz, @Nullable MediaType mediaType); /** * Write an given object to the given output message. @@ -98,7 +99,7 @@ public interface GenericHttpMessageConverter extends HttpMessageConverter * @throws HttpMessageNotWritableException in case of conversion errors * @since 4.2 */ - void write(T t, Type type, MediaType contentType, HttpOutputMessage outputMessage) + void write(T t, @Nullable Type type, @Nullable MediaType contentType, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException; } diff --git a/spring-web/src/main/java/org/springframework/http/converter/HttpMessageConversionException.java b/spring-web/src/main/java/org/springframework/http/converter/HttpMessageConversionException.java index b9fc38ff6c..0ce42ee938 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/HttpMessageConversionException.java +++ b/spring-web/src/main/java/org/springframework/http/converter/HttpMessageConversionException.java @@ -17,6 +17,7 @@ package org.springframework.http.converter; import org.springframework.core.NestedRuntimeException; +import org.springframework.lang.Nullable; /** * Thrown by {@link HttpMessageConverter} implementations when a conversion attempt fails. @@ -41,7 +42,7 @@ public class HttpMessageConversionException extends NestedRuntimeException { * @param msg the detail message * @param cause the root cause (if any) */ - public HttpMessageConversionException(String msg, Throwable cause) { + public HttpMessageConversionException(String msg, @Nullable Throwable cause) { super(msg, cause); } diff --git a/spring-web/src/main/java/org/springframework/http/converter/HttpMessageConverter.java b/spring-web/src/main/java/org/springframework/http/converter/HttpMessageConverter.java index 7cb9c6c61c..bfdd8741ff 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/HttpMessageConverter.java +++ b/spring-web/src/main/java/org/springframework/http/converter/HttpMessageConverter.java @@ -22,6 +22,7 @@ import java.util.List; import org.springframework.http.HttpInputMessage; import org.springframework.http.HttpOutputMessage; import org.springframework.http.MediaType; +import org.springframework.lang.Nullable; /** * Strategy interface that specifies a converter that can convert from and to HTTP requests and responses. @@ -39,7 +40,7 @@ public interface HttpMessageConverter { * typically the value of a {@code Content-Type} header. * @return {@code true} if readable; {@code false} otherwise */ - boolean canRead(Class clazz, MediaType mediaType); + boolean canRead(Class clazz, @Nullable MediaType mediaType); /** * Indicates whether the given class can be written by this converter. @@ -48,7 +49,7 @@ public interface HttpMessageConverter { * typically the value of an {@code Accept} header. * @return {@code true} if writable; {@code false} otherwise */ - boolean canWrite(Class clazz, MediaType mediaType); + boolean canWrite(Class clazz, @Nullable MediaType mediaType); /** * Return the list of {@link MediaType} objects supported by this converter. @@ -80,7 +81,7 @@ public interface HttpMessageConverter { * @throws IOException in case of I/O errors * @throws HttpMessageNotWritableException in case of conversion errors */ - void write(T t, MediaType contentType, HttpOutputMessage outputMessage) + void write(T t, @Nullable MediaType contentType, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException; } diff --git a/spring-web/src/main/java/org/springframework/http/converter/HttpMessageNotReadableException.java b/spring-web/src/main/java/org/springframework/http/converter/HttpMessageNotReadableException.java index 8d35ac90c3..0d3575d273 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/HttpMessageNotReadableException.java +++ b/spring-web/src/main/java/org/springframework/http/converter/HttpMessageNotReadableException.java @@ -16,6 +16,8 @@ package org.springframework.http.converter; +import org.springframework.lang.Nullable; + /** * Thrown by {@link HttpMessageConverter} implementations when the * {@link HttpMessageConverter#read} method fails. @@ -39,7 +41,7 @@ public class HttpMessageNotReadableException extends HttpMessageConversionExcept * @param msg the detail message * @param cause the root cause (if any) */ - public HttpMessageNotReadableException(String msg, Throwable cause) { + public HttpMessageNotReadableException(String msg, @Nullable Throwable cause) { super(msg, cause); } diff --git a/spring-web/src/main/java/org/springframework/http/converter/HttpMessageNotWritableException.java b/spring-web/src/main/java/org/springframework/http/converter/HttpMessageNotWritableException.java index 5eb5fa7117..beab170fe8 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/HttpMessageNotWritableException.java +++ b/spring-web/src/main/java/org/springframework/http/converter/HttpMessageNotWritableException.java @@ -16,6 +16,8 @@ package org.springframework.http.converter; +import org.springframework.lang.Nullable; + /** * Thrown by {@link HttpMessageConverter} implementations when the * {@link HttpMessageConverter#write} method fails. @@ -39,7 +41,7 @@ public class HttpMessageNotWritableException extends HttpMessageConversionExcept * @param msg the detail message * @param cause the root cause (if any) */ - public HttpMessageNotWritableException(String msg, Throwable cause) { + public HttpMessageNotWritableException(String msg, @Nullable Throwable cause) { super(msg, cause); } diff --git a/spring-web/src/main/java/org/springframework/http/converter/cbor/package-info.java b/spring-web/src/main/java/org/springframework/http/converter/cbor/package-info.java index 993f0e5f4d..62a839ae88 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/cbor/package-info.java +++ b/spring-web/src/main/java/org/springframework/http/converter/cbor/package-info.java @@ -1,4 +1,7 @@ /** * Provides an HttpMessageConverter for the CBOR data format. */ +@NonNullApi package org.springframework.http.converter.cbor; + +import org.springframework.lang.NonNullApi; diff --git a/spring-web/src/main/java/org/springframework/http/converter/feed/package-info.java b/spring-web/src/main/java/org/springframework/http/converter/feed/package-info.java index 440db3d377..3c4843aa18 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/feed/package-info.java +++ b/spring-web/src/main/java/org/springframework/http/converter/feed/package-info.java @@ -2,4 +2,7 @@ * Provides HttpMessageConverter implementations for handling Atom and RSS feeds. * Based on the ROME tools project. */ +@NonNullApi package org.springframework.http.converter.feed; + +import org.springframework.lang.NonNullApi; diff --git a/spring-web/src/main/java/org/springframework/http/converter/json/AbstractJackson2HttpMessageConverter.java b/spring-web/src/main/java/org/springframework/http/converter/json/AbstractJackson2HttpMessageConverter.java index d731af7f5e..82ee132804 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/json/AbstractJackson2HttpMessageConverter.java +++ b/spring-web/src/main/java/org/springframework/http/converter/json/AbstractJackson2HttpMessageConverter.java @@ -47,6 +47,7 @@ import org.springframework.http.converter.HttpMessageConversionException; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.HttpMessageNotReadableException; import org.springframework.http.converter.HttpMessageNotWritableException; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.TypeUtils; @@ -315,7 +316,7 @@ public abstract class AbstractJackson2HttpMessageConverter extends AbstractGener * in which the target type appears in a method signature (can be {@code null}) * @return the Jackson JavaType */ - protected JavaType getJavaType(Type type, Class contextClass) { + protected JavaType getJavaType(Type type, @Nullable Class contextClass) { TypeFactory typeFactory = this.objectMapper.getTypeFactory(); return typeFactory.constructType(GenericTypeResolver.resolveType(type, contextClass)); } diff --git a/spring-web/src/main/java/org/springframework/http/converter/json/AbstractJsonHttpMessageConverter.java b/spring-web/src/main/java/org/springframework/http/converter/json/AbstractJsonHttpMessageConverter.java index 4e5a7a4ce2..3684406b40 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/json/AbstractJsonHttpMessageConverter.java +++ b/spring-web/src/main/java/org/springframework/http/converter/json/AbstractJsonHttpMessageConverter.java @@ -33,6 +33,7 @@ import org.springframework.http.MediaType; import org.springframework.http.converter.AbstractGenericHttpMessageConverter; import org.springframework.http.converter.HttpMessageNotReadableException; import org.springframework.http.converter.HttpMessageNotWritableException; +import org.springframework.lang.Nullable; /** * Common base class for plain JSON converters, e.g. Gson and JSON-B. @@ -142,7 +143,7 @@ public abstract class AbstractJsonHttpMessageConverter extends AbstractGenericHt * @param writer the {@code} Writer to use * @throws Exception in case of write failures */ - protected abstract void writeInternal(Object o, Type type, Writer writer) throws Exception; + protected abstract void writeInternal(Object o, @Nullable Type type, Writer writer) throws Exception; private static Reader getReader(HttpInputMessage inputMessage) throws IOException { diff --git a/spring-web/src/main/java/org/springframework/http/converter/json/package-info.java b/spring-web/src/main/java/org/springframework/http/converter/json/package-info.java index 886aa94408..c786dae179 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/json/package-info.java +++ b/spring-web/src/main/java/org/springframework/http/converter/json/package-info.java @@ -1,4 +1,7 @@ /** * Provides HttpMessageConverter implementations for handling JSON. */ +@NonNullApi package org.springframework.http.converter.json; + +import org.springframework.lang.NonNullApi; diff --git a/spring-web/src/main/java/org/springframework/http/converter/package-info.java b/spring-web/src/main/java/org/springframework/http/converter/package-info.java index 0719dd82d3..e225736697 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/package-info.java +++ b/spring-web/src/main/java/org/springframework/http/converter/package-info.java @@ -1,4 +1,7 @@ /** * Provides an HttpMessageConverter abstraction to convert between Java objects and HTTP input/output messages. */ +@NonNullApi package org.springframework.http.converter; + +import org.springframework.lang.NonNullApi; diff --git a/spring-web/src/main/java/org/springframework/http/converter/protobuf/package-info.java b/spring-web/src/main/java/org/springframework/http/converter/protobuf/package-info.java index 3c73a272c5..863c73c5ae 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/protobuf/package-info.java +++ b/spring-web/src/main/java/org/springframework/http/converter/protobuf/package-info.java @@ -2,4 +2,7 @@ * Provides an HttpMessageConverter implementation for handling * Google Protocol Buffers. */ +@NonNullApi package org.springframework.http.converter.protobuf; + +import org.springframework.lang.NonNullApi; diff --git a/spring-web/src/main/java/org/springframework/http/converter/smile/package-info.java b/spring-web/src/main/java/org/springframework/http/converter/smile/package-info.java index a8e7e12106..1728559634 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/smile/package-info.java +++ b/spring-web/src/main/java/org/springframework/http/converter/smile/package-info.java @@ -1,4 +1,7 @@ /** * Provides an HttpMessageConverter for the Smile data format ("binary JSON"). */ +@NonNullApi package org.springframework.http.converter.smile; + +import org.springframework.lang.NonNullApi; diff --git a/spring-web/src/main/java/org/springframework/http/converter/support/package-info.java b/spring-web/src/main/java/org/springframework/http/converter/support/package-info.java index eaaf8204b4..33f91a24cf 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/support/package-info.java +++ b/spring-web/src/main/java/org/springframework/http/converter/support/package-info.java @@ -1,4 +1,7 @@ /** * Provides a comprehensive HttpMessageConverter variant for form handling. */ +@NonNullApi package org.springframework.http.converter.support; + +import org.springframework.lang.NonNullApi; diff --git a/spring-web/src/main/java/org/springframework/http/converter/xml/package-info.java b/spring-web/src/main/java/org/springframework/http/converter/xml/package-info.java index a889b35119..f3a33401d1 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/xml/package-info.java +++ b/spring-web/src/main/java/org/springframework/http/converter/xml/package-info.java @@ -1,4 +1,7 @@ /** * Provides HttpMessageConverter implementations for handling XML. */ +@NonNullApi package org.springframework.http.converter.xml; + +import org.springframework.lang.NonNullApi; diff --git a/spring-web/src/main/java/org/springframework/http/package-info.java b/spring-web/src/main/java/org/springframework/http/package-info.java index 0f7cce528b..04fddd7d6e 100644 --- a/spring-web/src/main/java/org/springframework/http/package-info.java +++ b/spring-web/src/main/java/org/springframework/http/package-info.java @@ -2,4 +2,7 @@ * Contains a basic abstraction over client/server-side HTTP. This package contains * the {@code HttpInputMessage} and {@code HttpOutputMessage} interfaces. */ +@NonNullApi package org.springframework.http; + +import org.springframework.lang.NonNullApi; diff --git a/spring-web/src/main/java/org/springframework/http/server/package-info.java b/spring-web/src/main/java/org/springframework/http/server/package-info.java index d08f8626a6..76ef93911b 100644 --- a/spring-web/src/main/java/org/springframework/http/server/package-info.java +++ b/spring-web/src/main/java/org/springframework/http/server/package-info.java @@ -3,4 +3,7 @@ * contains the {@code ServerHttpRequest} and {@code ServerHttpResponse}, * as well as a Servlet-based implementation of these interfaces. */ +@NonNullApi package org.springframework.http.server; + +import org.springframework.lang.NonNullApi; diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/AbstractListenerReadPublisher.java b/spring-web/src/main/java/org/springframework/http/server/reactive/AbstractListenerReadPublisher.java index d048891ae8..6df66b12f0 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/AbstractListenerReadPublisher.java +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/AbstractListenerReadPublisher.java @@ -27,6 +27,7 @@ import org.reactivestreams.Subscriber; import org.reactivestreams.Subscription; import reactor.core.publisher.Operators; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -108,6 +109,7 @@ public abstract class AbstractListenerReadPublisher implements Publisher { * Reads a data from the input, if possible. * @return the data that was read; or {@code null} */ + @Nullable protected abstract T read() throws IOException; diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/AbstractServerHttpResponse.java b/spring-web/src/main/java/org/springframework/http/server/reactive/AbstractServerHttpResponse.java index 42c4a50a0a..68d9cdcefd 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/AbstractServerHttpResponse.java +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/AbstractServerHttpResponse.java @@ -34,6 +34,7 @@ import org.springframework.core.io.buffer.DataBufferFactory; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseCookie; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.util.LinkedMultiValueMap; @@ -186,7 +187,7 @@ public abstract class AbstractServerHttpResponse implements ServerHttpResponse { * @param writeAction the action to write the response body (may be {@code null}) * @return a completion publisher */ - protected Mono doCommit(Supplier> writeAction) { + protected Mono doCommit(@Nullable Supplier> writeAction) { if (!this.state.compareAndSet(State.NEW, State.COMMITTING)) { if (logger.isDebugEnabled()) { logger.debug("Skipping doCommit (response already committed)."); diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/ServerHttpRequest.java b/spring-web/src/main/java/org/springframework/http/server/reactive/ServerHttpRequest.java index dac0090f5e..14d08e498a 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/ServerHttpRequest.java +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/ServerHttpRequest.java @@ -22,6 +22,7 @@ import org.springframework.http.HttpCookie; import org.springframework.http.HttpMethod; import org.springframework.http.HttpRequest; import org.springframework.http.ReactiveHttpInputMessage; +import org.springframework.lang.Nullable; import org.springframework.util.MultiValueMap; /** @@ -57,6 +58,7 @@ public interface ServerHttpRequest extends HttpRequest, ReactiveHttpInputMessage /** * Return the remote address where this request is connected to, if available. */ + @Nullable InetSocketAddress getRemoteAddress(); diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/ServerHttpResponse.java b/spring-web/src/main/java/org/springframework/http/server/reactive/ServerHttpResponse.java index e2b0b7a5dc..ce6534a473 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/ServerHttpResponse.java +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/ServerHttpResponse.java @@ -21,6 +21,7 @@ import java.util.function.Function; import org.springframework.http.HttpStatus; import org.springframework.http.ReactiveHttpOutputMessage; import org.springframework.http.ResponseCookie; +import org.springframework.lang.Nullable; import org.springframework.util.MultiValueMap; /** @@ -43,6 +44,7 @@ public interface ServerHttpResponse extends ReactiveHttpOutputMessage { /** * Return the HTTP status code or {@code null} if not set. */ + @Nullable HttpStatus getStatusCode(); /** diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/ServletHttpHandlerAdapter.java b/spring-web/src/main/java/org/springframework/http/server/reactive/ServletHttpHandlerAdapter.java index bded291e9f..e984d5f24b 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/ServletHttpHandlerAdapter.java +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/ServletHttpHandlerAdapter.java @@ -36,6 +36,7 @@ import org.reactivestreams.Subscription; import org.springframework.core.io.buffer.DataBufferFactory; import org.springframework.core.io.buffer.DefaultDataBufferFactory; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -133,6 +134,7 @@ public class ServletHttpHandlerAdapter implements Servlet { } @Override + @Nullable public ServletConfig getServletConfig() { return null; } diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/ServletServerHttpRequest.java b/spring-web/src/main/java/org/springframework/http/server/reactive/ServletServerHttpRequest.java index 08c51b62a6..072c0edd38 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/ServletServerHttpRequest.java +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/ServletServerHttpRequest.java @@ -40,6 +40,7 @@ import org.springframework.core.io.buffer.DataBufferFactory; import org.springframework.http.HttpCookie; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.LinkedCaseInsensitiveMap; import org.springframework.util.LinkedMultiValueMap; @@ -189,6 +190,7 @@ public class ServletServerHttpRequest extends AbstractServerHttpRequest { * Read from the request body InputStream and return a DataBuffer. * Invoked only when {@link ServletInputStream#isReady()} returns "true". */ + @Nullable protected DataBuffer readFromInputStream() throws IOException { int read = this.request.getInputStream().read(this.buffer); if (logger.isTraceEnabled()) { diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/package-info.java b/spring-web/src/main/java/org/springframework/http/server/reactive/package-info.java index 4c49c9e301..dcc0eb8f2d 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/package-info.java +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/package-info.java @@ -7,4 +7,7 @@ *

    Also provides implementations adapting to different runtimes * including Servlet 3.1 containers, Netty + Reactor IO, and Undertow. */ +@NonNullApi package org.springframework.http.server.reactive; + +import org.springframework.lang.NonNullApi; diff --git a/spring-web/src/main/java/org/springframework/remoting/caucho/package-info.java b/spring-web/src/main/java/org/springframework/remoting/caucho/package-info.java index e630835f26..bdb8b0e9d0 100644 --- a/spring-web/src/main/java/org/springframework/remoting/caucho/package-info.java +++ b/spring-web/src/main/java/org/springframework/remoting/caucho/package-info.java @@ -7,4 +7,7 @@ * For information on Hessian, see the * Hessian website */ +@NonNullApi package org.springframework.remoting.caucho; + +import org.springframework.lang.NonNullApi; diff --git a/spring-web/src/main/java/org/springframework/remoting/httpinvoker/AbstractHttpInvokerRequestExecutor.java b/spring-web/src/main/java/org/springframework/remoting/httpinvoker/AbstractHttpInvokerRequestExecutor.java index 2b976d32ec..8945db8b93 100644 --- a/spring-web/src/main/java/org/springframework/remoting/httpinvoker/AbstractHttpInvokerRequestExecutor.java +++ b/spring-web/src/main/java/org/springframework/remoting/httpinvoker/AbstractHttpInvokerRequestExecutor.java @@ -28,6 +28,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.BeanClassLoaderAware; +import org.springframework.lang.Nullable; import org.springframework.remoting.rmi.CodebaseAwareObjectInputStream; import org.springframework.remoting.support.RemoteInvocation; import org.springframework.remoting.support.RemoteInvocationResult; @@ -267,7 +268,7 @@ public abstract class AbstractHttpInvokerRequestExecutor implements HttpInvokerR * @throws IOException if creation of the ObjectInputStream failed * @see org.springframework.remoting.rmi.CodebaseAwareObjectInputStream */ - protected ObjectInputStream createObjectInputStream(InputStream is, String codebaseUrl) throws IOException { + protected ObjectInputStream createObjectInputStream(InputStream is, @Nullable String codebaseUrl) throws IOException { return new CodebaseAwareObjectInputStream(is, getBeanClassLoader(), codebaseUrl); } diff --git a/spring-web/src/main/java/org/springframework/remoting/httpinvoker/HttpComponentsHttpInvokerRequestExecutor.java b/spring-web/src/main/java/org/springframework/remoting/httpinvoker/HttpComponentsHttpInvokerRequestExecutor.java index 8ac5cf9228..53608ecf84 100644 --- a/spring-web/src/main/java/org/springframework/remoting/httpinvoker/HttpComponentsHttpInvokerRequestExecutor.java +++ b/spring-web/src/main/java/org/springframework/remoting/httpinvoker/HttpComponentsHttpInvokerRequestExecutor.java @@ -41,6 +41,7 @@ import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; import org.springframework.context.i18n.LocaleContext; import org.springframework.context.i18n.LocaleContextHolder; +import org.springframework.lang.Nullable; import org.springframework.remoting.support.RemoteInvocationResult; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -238,6 +239,7 @@ public class HttpComponentsHttpInvokerRequestExecutor extends AbstractHttpInvoke * target service * @return the RequestConfig to use */ + @Nullable protected RequestConfig createRequestConfig(HttpInvokerClientConfiguration config) { HttpClient client = getHttpClient(); if (client instanceof Configurable) { diff --git a/spring-web/src/main/java/org/springframework/remoting/httpinvoker/HttpInvokerClientConfiguration.java b/spring-web/src/main/java/org/springframework/remoting/httpinvoker/HttpInvokerClientConfiguration.java index 7e894a53e4..8ea6addc4e 100644 --- a/spring-web/src/main/java/org/springframework/remoting/httpinvoker/HttpInvokerClientConfiguration.java +++ b/spring-web/src/main/java/org/springframework/remoting/httpinvoker/HttpInvokerClientConfiguration.java @@ -16,6 +16,8 @@ package org.springframework.remoting.httpinvoker; +import org.springframework.lang.Nullable; + /** * Configuration interface for executing HTTP invoker requests. * @@ -37,6 +39,7 @@ public interface HttpInvokerClientConfiguration { * @return the codebase URL, or {@code null} if none * @see java.rmi.server.RMIClassLoader */ + @Nullable String getCodebaseUrl(); } diff --git a/spring-web/src/main/java/org/springframework/remoting/httpinvoker/HttpInvokerClientInterceptor.java b/spring-web/src/main/java/org/springframework/remoting/httpinvoker/HttpInvokerClientInterceptor.java index c6703e9d7f..3ff5a0f442 100644 --- a/spring-web/src/main/java/org/springframework/remoting/httpinvoker/HttpInvokerClientInterceptor.java +++ b/spring-web/src/main/java/org/springframework/remoting/httpinvoker/HttpInvokerClientInterceptor.java @@ -24,6 +24,7 @@ import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; import org.springframework.aop.support.AopUtils; +import org.springframework.lang.Nullable; import org.springframework.remoting.RemoteAccessException; import org.springframework.remoting.RemoteConnectFailureException; import org.springframework.remoting.RemoteInvocationFailureException; @@ -209,6 +210,7 @@ public class HttpInvokerClientInterceptor extends RemoteInvocationBasedAccessor * @return the RemoteAccessException to throw, or {@code null} to have the * original exception propagated to the caller */ + @Nullable protected RemoteAccessException convertHttpInvokerAccessException(Throwable ex) { if (ex instanceof ConnectException) { return new RemoteConnectFailureException( diff --git a/spring-web/src/main/java/org/springframework/remoting/httpinvoker/package-info.java b/spring-web/src/main/java/org/springframework/remoting/httpinvoker/package-info.java index c145ec2455..1409b7b049 100644 --- a/spring-web/src/main/java/org/springframework/remoting/httpinvoker/package-info.java +++ b/spring-web/src/main/java/org/springframework/remoting/httpinvoker/package-info.java @@ -8,4 +8,7 @@ * being tied to Java. Nevertheless, it is as easy to set up as Hessian, * which is its main advantage compared to RMI. */ +@NonNullApi package org.springframework.remoting.httpinvoker; + +import org.springframework.lang.NonNullApi; diff --git a/spring-web/src/main/java/org/springframework/remoting/jaxws/JaxWsPortClientInterceptor.java b/spring-web/src/main/java/org/springframework/remoting/jaxws/JaxWsPortClientInterceptor.java index a1d6d32e42..edebde3279 100644 --- a/spring-web/src/main/java/org/springframework/remoting/jaxws/JaxWsPortClientInterceptor.java +++ b/spring-web/src/main/java/org/springframework/remoting/jaxws/JaxWsPortClientInterceptor.java @@ -37,6 +37,7 @@ import org.aopalliance.intercept.MethodInvocation; import org.springframework.aop.support.AopUtils; import org.springframework.beans.factory.BeanClassLoaderAware; import org.springframework.beans.factory.InitializingBean; +import org.springframework.lang.Nullable; import org.springframework.remoting.RemoteAccessException; import org.springframework.remoting.RemoteConnectFailureException; import org.springframework.remoting.RemoteLookupFailureException; @@ -112,6 +113,7 @@ public class JaxWsPortClientInterceptor extends LocalJaxWsServiceFactory /** * Return a reference to an existing JAX-WS Service instance, if any. */ + @Nullable public Service getJaxWsService() { return this.jaxWsService; } @@ -491,6 +493,7 @@ public class JaxWsPortClientInterceptor extends LocalJaxWsServiceFactory * @see #getPortStub() * @see #doInvoke(org.aopalliance.intercept.MethodInvocation, Object) */ + @Nullable protected Object doInvoke(MethodInvocation invocation) throws Throwable { try { return doInvoke(invocation, getPortStub()); @@ -516,6 +519,7 @@ public class JaxWsPortClientInterceptor extends LocalJaxWsServiceFactory * @throws Throwable in case of invocation failure * @see #getPortStub() */ + @Nullable protected Object doInvoke(MethodInvocation invocation, Object portStub) throws Throwable { Method method = invocation.getMethod(); try { diff --git a/spring-web/src/main/java/org/springframework/remoting/jaxws/package-info.java b/spring-web/src/main/java/org/springframework/remoting/jaxws/package-info.java index ba98b1aa39..e8f54f8810 100644 --- a/spring-web/src/main/java/org/springframework/remoting/jaxws/package-info.java +++ b/spring-web/src/main/java/org/springframework/remoting/jaxws/package-info.java @@ -3,4 +3,7 @@ * as included in Java 6 and Java EE 5. This package provides proxy * factories for accessing JAX-WS services and ports. */ +@NonNullApi package org.springframework.remoting.jaxws; + +import org.springframework.lang.NonNullApi; diff --git a/spring-web/src/main/java/org/springframework/web/HttpRequestMethodNotSupportedException.java b/spring-web/src/main/java/org/springframework/web/HttpRequestMethodNotSupportedException.java index bc13568dc7..c4fe79a798 100644 --- a/spring-web/src/main/java/org/springframework/web/HttpRequestMethodNotSupportedException.java +++ b/spring-web/src/main/java/org/springframework/web/HttpRequestMethodNotSupportedException.java @@ -21,9 +21,11 @@ import java.util.EnumSet; import java.util.LinkedList; import java.util.List; import java.util.Set; + import javax.servlet.ServletException; import org.springframework.http.HttpMethod; +import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; /** @@ -63,7 +65,7 @@ public class HttpRequestMethodNotSupportedException extends ServletException { * @param method the unsupported HTTP request method * @param supportedMethods the actually supported HTTP methods (may be {@code null}) */ - public HttpRequestMethodNotSupportedException(String method, Collection supportedMethods) { + public HttpRequestMethodNotSupportedException(String method, @Nullable Collection supportedMethods) { this(method, StringUtils.toStringArray(supportedMethods)); } @@ -72,7 +74,7 @@ public class HttpRequestMethodNotSupportedException extends ServletException { * @param method the unsupported HTTP request method * @param supportedMethods the actually supported HTTP methods (may be {@code null}) */ - public HttpRequestMethodNotSupportedException(String method, String[] supportedMethods) { + public HttpRequestMethodNotSupportedException(String method, @Nullable String[] supportedMethods) { this(method, supportedMethods, "Request method '" + method + "' not supported"); } @@ -99,6 +101,7 @@ public class HttpRequestMethodNotSupportedException extends ServletException { /** * Return the actually supported HTTP methods, or {@code null} if not known. */ + @Nullable public String[] getSupportedMethods() { return this.supportedMethods; } @@ -108,6 +111,7 @@ public class HttpRequestMethodNotSupportedException extends ServletException { * or {@code null} if not known. * @since 3.2 */ + @Nullable public Set getSupportedHttpMethods() { if (this.supportedMethods == null) { return null; diff --git a/spring-web/src/main/java/org/springframework/web/HttpSessionRequiredException.java b/spring-web/src/main/java/org/springframework/web/HttpSessionRequiredException.java index d17f8d39f9..7b5f1d3bf0 100644 --- a/spring-web/src/main/java/org/springframework/web/HttpSessionRequiredException.java +++ b/spring-web/src/main/java/org/springframework/web/HttpSessionRequiredException.java @@ -18,6 +18,8 @@ package org.springframework.web; import javax.servlet.ServletException; +import org.springframework.lang.Nullable; + /** * Exception thrown when an HTTP request handler requires a pre-existing session. * @@ -54,6 +56,7 @@ public class HttpSessionRequiredException extends ServletException { * Return the name of the expected session attribute, if any. * @since 4.3 */ + @Nullable public String getExpectedAttribute() { return this.expectedAttribute; } diff --git a/spring-web/src/main/java/org/springframework/web/accept/AbstractMappingContentNegotiationStrategy.java b/spring-web/src/main/java/org/springframework/web/accept/AbstractMappingContentNegotiationStrategy.java index ee83d31f77..4ee7cf6f80 100644 --- a/spring-web/src/main/java/org/springframework/web/accept/AbstractMappingContentNegotiationStrategy.java +++ b/spring-web/src/main/java/org/springframework/web/accept/AbstractMappingContentNegotiationStrategy.java @@ -21,6 +21,7 @@ import java.util.List; import java.util.Map; import org.springframework.http.MediaType; +import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; import org.springframework.web.HttpMediaTypeNotAcceptableException; import org.springframework.web.context.request.NativeWebRequest; @@ -89,6 +90,7 @@ public abstract class AbstractMappingContentNegotiationStrategy extends MappingM * Extract a key from the request to use to look up media types. * @return the lookup key or {@code null}. */ + @Nullable protected abstract String getMediaTypeKey(NativeWebRequest request); /** @@ -104,6 +106,7 @@ public abstract class AbstractMappingContentNegotiationStrategy extends MappingM * determine the media type(s). If a MediaType is returned from * this method it will be added to the cache in the base class. */ + @Nullable protected MediaType handleNoMatch(NativeWebRequest request, String key) throws HttpMediaTypeNotAcceptableException { diff --git a/spring-web/src/main/java/org/springframework/web/accept/ContentNegotiationManager.java b/spring-web/src/main/java/org/springframework/web/accept/ContentNegotiationManager.java index 04184f5bb5..9262100695 100644 --- a/spring-web/src/main/java/org/springframework/web/accept/ContentNegotiationManager.java +++ b/spring-web/src/main/java/org/springframework/web/accept/ContentNegotiationManager.java @@ -25,6 +25,7 @@ import java.util.List; import java.util.Set; import org.springframework.http.MediaType; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.HttpMediaTypeNotAcceptableException; import org.springframework.web.context.request.NativeWebRequest; @@ -99,6 +100,7 @@ public class ContentNegotiationManager implements ContentNegotiationStrategy, Me * @since 4.3 */ @SuppressWarnings("unchecked") + @Nullable public T getStrategy(Class strategyType) { for (ContentNegotiationStrategy strategy : getStrategies()) { if (strategyType.isInstance(strategy)) { diff --git a/spring-web/src/main/java/org/springframework/web/accept/MappingMediaTypeFileExtensionResolver.java b/spring-web/src/main/java/org/springframework/web/accept/MappingMediaTypeFileExtensionResolver.java index 4d9d84117a..31dd0072df 100644 --- a/spring-web/src/main/java/org/springframework/web/accept/MappingMediaTypeFileExtensionResolver.java +++ b/spring-web/src/main/java/org/springframework/web/accept/MappingMediaTypeFileExtensionResolver.java @@ -27,6 +27,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import org.springframework.http.MediaType; +import org.springframework.lang.Nullable; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; @@ -102,6 +103,7 @@ public class MappingMediaTypeFileExtensionResolver implements MediaTypeFileExten * Use this method for a reverse lookup from extension to MediaType. * @return a MediaType for the key, or {@code null} if none found */ + @Nullable protected MediaType lookupMediaType(String extension) { return this.mediaTypes.get(extension.toLowerCase(Locale.ENGLISH)); } diff --git a/spring-web/src/main/java/org/springframework/web/accept/PathExtensionContentNegotiationStrategy.java b/spring-web/src/main/java/org/springframework/web/accept/PathExtensionContentNegotiationStrategy.java index 8e0a1b7ecb..e09332f9b1 100644 --- a/spring-web/src/main/java/org/springframework/web/accept/PathExtensionContentNegotiationStrategy.java +++ b/spring-web/src/main/java/org/springframework/web/accept/PathExtensionContentNegotiationStrategy.java @@ -19,6 +19,7 @@ package org.springframework.web.accept; import java.util.Locale; import java.util.Map; import java.util.Optional; + import javax.servlet.http.HttpServletRequest; import org.apache.commons.logging.Log; @@ -27,6 +28,7 @@ import org.apache.commons.logging.LogFactory; import org.springframework.core.io.Resource; import org.springframework.http.MediaType; import org.springframework.http.MediaTypeFactory; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.StringUtils; import org.springframework.web.HttpMediaTypeNotAcceptableException; @@ -146,6 +148,7 @@ public class PathExtensionContentNegotiationStrategy extends AbstractMappingCont * @return the MediaType for the extension, or {@code null} if none found * @since 4.3 */ + @Nullable public MediaType getMediaTypeForResource(Resource resource) { Assert.notNull(resource, "Resource must not be null"); MediaType mediaType = null; diff --git a/spring-web/src/main/java/org/springframework/web/accept/ServletPathExtensionContentNegotiationStrategy.java b/spring-web/src/main/java/org/springframework/web/accept/ServletPathExtensionContentNegotiationStrategy.java index 86a212e50a..1fa2d28ba3 100644 --- a/spring-web/src/main/java/org/springframework/web/accept/ServletPathExtensionContentNegotiationStrategy.java +++ b/spring-web/src/main/java/org/springframework/web/accept/ServletPathExtensionContentNegotiationStrategy.java @@ -17,6 +17,7 @@ package org.springframework.web.accept; import java.util.Map; + import javax.servlet.ServletContext; import org.springframework.core.io.Resource; diff --git a/spring-web/src/main/java/org/springframework/web/accept/package-info.java b/spring-web/src/main/java/org/springframework/web/accept/package-info.java index d3c5ba3e16..111a11ed3e 100644 --- a/spring-web/src/main/java/org/springframework/web/accept/package-info.java +++ b/spring-web/src/main/java/org/springframework/web/accept/package-info.java @@ -12,4 +12,7 @@ *

    {@link org.springframework.web.accept.ContentNegotiationManager} is used to delegate to one * ore more of the above strategies in a specific order. */ +@NonNullApi package org.springframework.web.accept; + +import org.springframework.lang.NonNullApi; diff --git a/spring-web/src/main/java/org/springframework/web/bind/ServletRequestDataBinder.java b/spring-web/src/main/java/org/springframework/web/bind/ServletRequestDataBinder.java index ad651bbe28..77be69a304 100644 --- a/spring-web/src/main/java/org/springframework/web/bind/ServletRequestDataBinder.java +++ b/spring-web/src/main/java/org/springframework/web/bind/ServletRequestDataBinder.java @@ -19,6 +19,7 @@ package org.springframework.web.bind; import javax.servlet.ServletRequest; import org.springframework.beans.MutablePropertyValues; +import org.springframework.lang.Nullable; import org.springframework.validation.BindException; import org.springframework.web.multipart.MultipartRequest; import org.springframework.web.util.WebUtils; @@ -64,7 +65,7 @@ public class ServletRequestDataBinder extends WebDataBinder { * if the binder is just used to convert a plain parameter value) * @see #DEFAULT_OBJECT_NAME */ - public ServletRequestDataBinder(Object target) { + public ServletRequestDataBinder(@Nullable Object target) { super(target); } @@ -74,7 +75,7 @@ public class ServletRequestDataBinder extends WebDataBinder { * if the binder is just used to convert a plain parameter value) * @param objectName the name of the target object */ - public ServletRequestDataBinder(Object target, String objectName) { + public ServletRequestDataBinder(@Nullable Object target, String objectName) { super(target, objectName); } diff --git a/spring-web/src/main/java/org/springframework/web/bind/ServletRequestUtils.java b/spring-web/src/main/java/org/springframework/web/bind/ServletRequestUtils.java index 0745e9494f..8c247d6faa 100644 --- a/spring-web/src/main/java/org/springframework/web/bind/ServletRequestUtils.java +++ b/spring-web/src/main/java/org/springframework/web/bind/ServletRequestUtils.java @@ -18,6 +18,8 @@ package org.springframework.web.bind; import javax.servlet.ServletRequest; +import org.springframework.lang.Nullable; + /** * Parameter extraction methods, for an approach distinct from data binding, * in which parameters of specific types are required. @@ -53,6 +55,7 @@ public abstract class ServletRequestUtils { * @throws ServletRequestBindingException a subclass of ServletException, * so it doesn't need to be caught */ + @Nullable public static Integer getIntParameter(ServletRequest request, String name) throws ServletRequestBindingException { @@ -131,6 +134,7 @@ public abstract class ServletRequestUtils { * @throws ServletRequestBindingException a subclass of ServletException, * so it doesn't need to be caught */ + @Nullable public static Long getLongParameter(ServletRequest request, String name) throws ServletRequestBindingException { @@ -209,6 +213,7 @@ public abstract class ServletRequestUtils { * @throws ServletRequestBindingException a subclass of ServletException, * so it doesn't need to be caught */ + @Nullable public static Float getFloatParameter(ServletRequest request, String name) throws ServletRequestBindingException { @@ -287,6 +292,7 @@ public abstract class ServletRequestUtils { * @throws ServletRequestBindingException a subclass of ServletException, * so it doesn't need to be caught */ + @Nullable public static Double getDoubleParameter(ServletRequest request, String name) throws ServletRequestBindingException { @@ -367,6 +373,7 @@ public abstract class ServletRequestUtils { * @throws ServletRequestBindingException a subclass of ServletException, * so it doesn't need to be caught */ + @Nullable public static Boolean getBooleanParameter(ServletRequest request, String name) throws ServletRequestBindingException { @@ -454,6 +461,7 @@ public abstract class ServletRequestUtils { * @throws ServletRequestBindingException a subclass of ServletException, * so it doesn't need to be caught */ + @Nullable public static String getStringParameter(ServletRequest request, String name) throws ServletRequestBindingException { diff --git a/spring-web/src/main/java/org/springframework/web/bind/WebDataBinder.java b/spring-web/src/main/java/org/springframework/web/bind/WebDataBinder.java index 48756e854a..1ad598224f 100644 --- a/spring-web/src/main/java/org/springframework/web/bind/WebDataBinder.java +++ b/spring-web/src/main/java/org/springframework/web/bind/WebDataBinder.java @@ -24,6 +24,7 @@ import java.util.Map; import org.springframework.beans.MutablePropertyValues; import org.springframework.beans.PropertyValue; import org.springframework.core.CollectionFactory; +import org.springframework.lang.Nullable; import org.springframework.validation.DataBinder; import org.springframework.web.multipart.MultipartFile; @@ -87,7 +88,7 @@ public class WebDataBinder extends DataBinder { * if the binder is just used to convert a plain parameter value) * @see #DEFAULT_OBJECT_NAME */ - public WebDataBinder(Object target) { + public WebDataBinder(@Nullable Object target) { super(target); } @@ -97,7 +98,7 @@ public class WebDataBinder extends DataBinder { * if the binder is just used to convert a plain parameter value) * @param objectName the name of the target object */ - public WebDataBinder(Object target, String objectName) { + public WebDataBinder(@Nullable Object target, String objectName) { super(target, objectName); } @@ -258,7 +259,8 @@ public class WebDataBinder extends DataBinder { * @param fieldType the type of the field * @return the empty value (for most fields: null) */ - protected Object getEmptyValue(String field, Class fieldType) { + @Nullable + protected Object getEmptyValue(String field, @Nullable Class fieldType) { if (fieldType != null) { try { if (boolean.class == fieldType || Boolean.class == fieldType) { diff --git a/spring-web/src/main/java/org/springframework/web/bind/annotation/package-info.java b/spring-web/src/main/java/org/springframework/web/bind/annotation/package-info.java index a11e561edd..73ccba5ce4 100644 --- a/spring-web/src/main/java/org/springframework/web/bind/annotation/package-info.java +++ b/spring-web/src/main/java/org/springframework/web/bind/annotation/package-info.java @@ -2,4 +2,7 @@ * Annotations for binding requests to controllers and handler methods * as well as for binding request parameters to method arguments. */ +@NonNullApi package org.springframework.web.bind.annotation; + +import org.springframework.lang.NonNullApi; diff --git a/spring-web/src/main/java/org/springframework/web/bind/package-info.java b/spring-web/src/main/java/org/springframework/web/bind/package-info.java index fca046be7c..c0b9c54c81 100644 --- a/spring-web/src/main/java/org/springframework/web/bind/package-info.java +++ b/spring-web/src/main/java/org/springframework/web/bind/package-info.java @@ -1,4 +1,7 @@ /** * Provides web-specific data binding functionality. */ +@NonNullApi package org.springframework.web.bind; + +import org.springframework.lang.NonNullApi; diff --git a/spring-web/src/main/java/org/springframework/web/bind/support/ConfigurableWebBindingInitializer.java b/spring-web/src/main/java/org/springframework/web/bind/support/ConfigurableWebBindingInitializer.java index acb3a45981..5781908384 100644 --- a/spring-web/src/main/java/org/springframework/web/bind/support/ConfigurableWebBindingInitializer.java +++ b/spring-web/src/main/java/org/springframework/web/bind/support/ConfigurableWebBindingInitializer.java @@ -18,6 +18,7 @@ package org.springframework.web.bind.support; import org.springframework.beans.PropertyEditorRegistrar; import org.springframework.core.convert.ConversionService; +import org.springframework.lang.Nullable; import org.springframework.validation.BindingErrorProcessor; import org.springframework.validation.MessageCodesResolver; import org.springframework.validation.Validator; @@ -107,6 +108,7 @@ public class ConfigurableWebBindingInitializer implements WebBindingInitializer /** * Return the strategy to use for resolving errors into message codes. */ + @Nullable public final MessageCodesResolver getMessageCodesResolver() { return this.messageCodesResolver; } @@ -125,6 +127,7 @@ public class ConfigurableWebBindingInitializer implements WebBindingInitializer /** * Return the strategy to use for processing binding errors. */ + @Nullable public final BindingErrorProcessor getBindingErrorProcessor() { return this.bindingErrorProcessor; } @@ -139,6 +142,7 @@ public class ConfigurableWebBindingInitializer implements WebBindingInitializer /** * Return the Validator to apply after each binding step, if any. */ + @Nullable public final Validator getValidator() { return this.validator; } @@ -154,6 +158,7 @@ public class ConfigurableWebBindingInitializer implements WebBindingInitializer /** * Return the ConversionService which will apply to every DataBinder. */ + @Nullable public final ConversionService getConversionService() { return this.conversionService; } @@ -175,6 +180,7 @@ public class ConfigurableWebBindingInitializer implements WebBindingInitializer /** * Return the PropertyEditorRegistrars to be applied to every DataBinder. */ + @Nullable public final PropertyEditorRegistrar[] getPropertyEditorRegistrars() { return this.propertyEditorRegistrars; } diff --git a/spring-web/src/main/java/org/springframework/web/bind/support/DefaultDataBinderFactory.java b/spring-web/src/main/java/org/springframework/web/bind/support/DefaultDataBinderFactory.java index 53e5a0abd0..df98d87019 100644 --- a/spring-web/src/main/java/org/springframework/web/bind/support/DefaultDataBinderFactory.java +++ b/spring-web/src/main/java/org/springframework/web/bind/support/DefaultDataBinderFactory.java @@ -16,6 +16,7 @@ package org.springframework.web.bind.support; +import org.springframework.lang.Nullable; import org.springframework.web.bind.WebDataBinder; import org.springframework.web.context.request.NativeWebRequest; @@ -36,7 +37,7 @@ public class DefaultDataBinderFactory implements WebDataBinderFactory { * @param initializer for global data binder initialization * (or {@code null} if none) */ - public DefaultDataBinderFactory(WebBindingInitializer initializer) { + public DefaultDataBinderFactory(@Nullable WebBindingInitializer initializer) { this.initializer = initializer; } @@ -67,7 +68,7 @@ public class DefaultDataBinderFactory implements WebDataBinderFactory { * @param webRequest the current request * @throws Exception in case of invalid state or arguments */ - protected WebDataBinder createBinderInstance(Object target, String objectName, + protected WebDataBinder createBinderInstance(@Nullable Object target, String objectName, NativeWebRequest webRequest) throws Exception { return new WebRequestDataBinder(target, objectName); diff --git a/spring-web/src/main/java/org/springframework/web/bind/support/SessionAttributeStore.java b/spring-web/src/main/java/org/springframework/web/bind/support/SessionAttributeStore.java index 47a9b103c7..7f0b2b6b13 100644 --- a/spring-web/src/main/java/org/springframework/web/bind/support/SessionAttributeStore.java +++ b/spring-web/src/main/java/org/springframework/web/bind/support/SessionAttributeStore.java @@ -16,6 +16,7 @@ package org.springframework.web.bind.support; +import org.springframework.lang.Nullable; import org.springframework.web.context.request.WebRequest; /** @@ -46,6 +47,7 @@ public interface SessionAttributeStore { * @param attributeName the name of the attribute * @return the current attribute value, or {@code null} if none */ + @Nullable Object retrieveAttribute(WebRequest request, String attributeName); /** diff --git a/spring-web/src/main/java/org/springframework/web/bind/support/WebDataBinderFactory.java b/spring-web/src/main/java/org/springframework/web/bind/support/WebDataBinderFactory.java index e37776a3c8..1e2d369300 100644 --- a/spring-web/src/main/java/org/springframework/web/bind/support/WebDataBinderFactory.java +++ b/spring-web/src/main/java/org/springframework/web/bind/support/WebDataBinderFactory.java @@ -16,6 +16,7 @@ package org.springframework.web.bind.support; +import org.springframework.lang.Nullable; import org.springframework.web.bind.WebDataBinder; import org.springframework.web.context.request.NativeWebRequest; @@ -35,6 +36,6 @@ public interface WebDataBinderFactory { * @return the created {@link WebDataBinder} instance, never null * @throws Exception raised if the creation and initialization of the data binder fails */ - WebDataBinder createBinder(NativeWebRequest webRequest, Object target, String objectName) throws Exception; + WebDataBinder createBinder(NativeWebRequest webRequest, @Nullable Object target, String objectName) throws Exception; } diff --git a/spring-web/src/main/java/org/springframework/web/bind/support/WebExchangeDataBinder.java b/spring-web/src/main/java/org/springframework/web/bind/support/WebExchangeDataBinder.java index d3ccb61689..7ff87b54f7 100644 --- a/spring-web/src/main/java/org/springframework/web/bind/support/WebExchangeDataBinder.java +++ b/spring-web/src/main/java/org/springframework/web/bind/support/WebExchangeDataBinder.java @@ -26,6 +26,7 @@ import reactor.core.publisher.Mono; import org.springframework.beans.MutablePropertyValues; import org.springframework.http.codec.multipart.FormFieldPart; import org.springframework.http.codec.multipart.Part; +import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; import org.springframework.util.MultiValueMap; import org.springframework.web.bind.WebDataBinder; @@ -47,7 +48,7 @@ public class WebExchangeDataBinder extends WebDataBinder { * binder is just used to convert a plain parameter value) * @see #DEFAULT_OBJECT_NAME */ - public WebExchangeDataBinder(Object target) { + public WebExchangeDataBinder(@Nullable Object target) { super(target); } @@ -57,7 +58,7 @@ public class WebExchangeDataBinder extends WebDataBinder { * binder is just used to convert a plain parameter value) * @param objectName the name of the target object */ - public WebExchangeDataBinder(Object target, String objectName) { + public WebExchangeDataBinder(@Nullable Object target, String objectName) { super(target, objectName); } diff --git a/spring-web/src/main/java/org/springframework/web/bind/support/WebRequestDataBinder.java b/spring-web/src/main/java/org/springframework/web/bind/support/WebRequestDataBinder.java index 7841d5b951..05886258f8 100644 --- a/spring-web/src/main/java/org/springframework/web/bind/support/WebRequestDataBinder.java +++ b/spring-web/src/main/java/org/springframework/web/bind/support/WebRequestDataBinder.java @@ -18,10 +18,12 @@ package org.springframework.web.bind.support; import java.util.List; import java.util.Map; + import javax.servlet.http.HttpServletRequest; import javax.servlet.http.Part; import org.springframework.beans.MutablePropertyValues; +import org.springframework.lang.Nullable; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.util.StringUtils; @@ -75,7 +77,7 @@ public class WebRequestDataBinder extends WebDataBinder { * if the binder is just used to convert a plain parameter value) * @see #DEFAULT_OBJECT_NAME */ - public WebRequestDataBinder(Object target) { + public WebRequestDataBinder(@Nullable Object target) { super(target); } @@ -85,7 +87,7 @@ public class WebRequestDataBinder extends WebDataBinder { * if the binder is just used to convert a plain parameter value) * @param objectName the name of the target object */ - public WebRequestDataBinder(Object target, String objectName) { + public WebRequestDataBinder(@Nullable Object target, String objectName) { super(target, objectName); } diff --git a/spring-web/src/main/java/org/springframework/web/bind/support/package-info.java b/spring-web/src/main/java/org/springframework/web/bind/support/package-info.java index 49a9e2a939..2731b4f638 100644 --- a/spring-web/src/main/java/org/springframework/web/bind/support/package-info.java +++ b/spring-web/src/main/java/org/springframework/web/bind/support/package-info.java @@ -1,4 +1,7 @@ /** * Support classes for web data binding. */ +@NonNullApi package org.springframework.web.bind.support; + +import org.springframework.lang.NonNullApi; diff --git a/spring-web/src/main/java/org/springframework/web/client/AsyncRestOperations.java b/spring-web/src/main/java/org/springframework/web/client/AsyncRestOperations.java index a4f77d671f..2dda684317 100644 --- a/spring-web/src/main/java/org/springframework/web/client/AsyncRestOperations.java +++ b/spring-web/src/main/java/org/springframework/web/client/AsyncRestOperations.java @@ -26,6 +26,7 @@ import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; +import org.springframework.lang.Nullable; import org.springframework.util.concurrent.ListenableFuture; /** @@ -128,7 +129,7 @@ public interface AsyncRestOperations { * @return the value for the {@code Location} header wrapped in a {@link Future} * @see org.springframework.http.HttpEntity */ - ListenableFuture postForLocation(String url, HttpEntity request, Object... uriVariables) + ListenableFuture postForLocation(String url, @Nullable HttpEntity request, Object... uriVariables) throws RestClientException; /** @@ -142,7 +143,7 @@ public interface AsyncRestOperations { * @return the value for the {@code Location} header wrapped in a {@link Future} * @see org.springframework.http.HttpEntity */ - ListenableFuture postForLocation(String url, HttpEntity request, Map uriVariables) + ListenableFuture postForLocation(String url, @Nullable HttpEntity request, Map uriVariables) throws RestClientException; /** @@ -154,7 +155,7 @@ public interface AsyncRestOperations { * @return the value for the {@code Location} header wrapped in a {@link Future} * @see org.springframework.http.HttpEntity */ - ListenableFuture postForLocation(URI url, HttpEntity request) throws RestClientException; + ListenableFuture postForLocation(URI url, @Nullable HttpEntity request) throws RestClientException; /** * Create a new resource by POSTing the given object to the URI template, @@ -166,7 +167,7 @@ public interface AsyncRestOperations { * @return the entity wrapped in a {@link Future} * @see org.springframework.http.HttpEntity */ - ListenableFuture> postForEntity(String url, HttpEntity request, + ListenableFuture> postForEntity(String url, @Nullable HttpEntity request, Class responseType, Object... uriVariables) throws RestClientException; /** @@ -179,7 +180,7 @@ public interface AsyncRestOperations { * @return the entity wrapped in a {@link Future} * @see org.springframework.http.HttpEntity */ - ListenableFuture> postForEntity(String url, HttpEntity request, + ListenableFuture> postForEntity(String url, @Nullable HttpEntity request, Class responseType, Map uriVariables) throws RestClientException; /** @@ -190,7 +191,7 @@ public interface AsyncRestOperations { * @return the entity wrapped in a {@link Future} * @see org.springframework.http.HttpEntity */ - ListenableFuture> postForEntity(URI url, HttpEntity request, + ListenableFuture> postForEntity(URI url, @Nullable HttpEntity request, Class responseType) throws RestClientException; @@ -205,7 +206,7 @@ public interface AsyncRestOperations { * @param uriVariables the variables to expand the template * @see HttpEntity */ - ListenableFuture put(String url, HttpEntity request, Object... uriVariables) + ListenableFuture put(String url, @Nullable HttpEntity request, Object... uriVariables) throws RestClientException; /** @@ -217,7 +218,7 @@ public interface AsyncRestOperations { * @param uriVariables the variables to expand the template * @see HttpEntity */ - ListenableFuture put(String url, HttpEntity request, Map uriVariables) + ListenableFuture put(String url, @Nullable HttpEntity request, Map uriVariables) throws RestClientException; /** @@ -227,7 +228,7 @@ public interface AsyncRestOperations { * @param request the Object to be PUT (may be {@code null}) * @see HttpEntity */ - ListenableFuture put(URI url, HttpEntity request) throws RestClientException; + ListenableFuture put(URI url, @Nullable HttpEntity request) throws RestClientException; // DELETE @@ -305,7 +306,7 @@ public interface AsyncRestOperations { * @return the response as entity wrapped in a {@link Future} */ ListenableFuture> exchange(String url, HttpMethod method, - HttpEntity requestEntity, Class responseType, Object... uriVariables) + @Nullable HttpEntity requestEntity, Class responseType, Object... uriVariables) throws RestClientException; /** @@ -322,7 +323,7 @@ public interface AsyncRestOperations { * @return the response as entity wrapped in a {@link Future} */ ListenableFuture> exchange(String url, HttpMethod method, - HttpEntity requestEntity, Class responseType, + @Nullable HttpEntity requestEntity, Class responseType, Map uriVariables) throws RestClientException; /** @@ -337,7 +338,7 @@ public interface AsyncRestOperations { * @return the response as entity wrapped in a {@link Future} */ ListenableFuture> exchange(URI url, HttpMethod method, - HttpEntity requestEntity, Class responseType) + @Nullable HttpEntity requestEntity, Class responseType) throws RestClientException; /** @@ -358,7 +359,7 @@ public interface AsyncRestOperations { * @return the response as entity wrapped in a {@link Future} */ ListenableFuture> exchange(String url, HttpMethod method, - HttpEntity requestEntity, ParameterizedTypeReference responseType, + @Nullable HttpEntity requestEntity, ParameterizedTypeReference responseType, Object... uriVariables) throws RestClientException; /** @@ -379,7 +380,7 @@ public interface AsyncRestOperations { * @return the response as entity wrapped in a {@link Future} */ ListenableFuture> exchange(String url, HttpMethod method, - HttpEntity requestEntity, ParameterizedTypeReference responseType, + @Nullable HttpEntity requestEntity, ParameterizedTypeReference responseType, Map uriVariables) throws RestClientException; /** @@ -399,7 +400,7 @@ public interface AsyncRestOperations { * @return the response as entity wrapped in a {@link Future} */ ListenableFuture> exchange(URI url, HttpMethod method, - HttpEntity requestEntity, ParameterizedTypeReference responseType) + @Nullable HttpEntity requestEntity, ParameterizedTypeReference responseType) throws RestClientException; diff --git a/spring-web/src/main/java/org/springframework/web/client/AsyncRestTemplate.java b/spring-web/src/main/java/org/springframework/web/client/AsyncRestTemplate.java index 7f034ca07c..b48cff0f2c 100644 --- a/spring-web/src/main/java/org/springframework/web/client/AsyncRestTemplate.java +++ b/spring-web/src/main/java/org/springframework/web/client/AsyncRestTemplate.java @@ -38,6 +38,7 @@ import org.springframework.http.client.ClientHttpRequestFactory; import org.springframework.http.client.ClientHttpResponse; import org.springframework.http.client.SimpleClientHttpRequestFactory; import org.springframework.http.converter.HttpMessageConverter; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.concurrent.ListenableFuture; import org.springframework.util.concurrent.ListenableFutureAdapter; @@ -498,8 +499,8 @@ public class AsyncRestTemplate extends org.springframework.http.client.support.I * be {@code null}) * @return an arbitrary object, as returned by the {@link ResponseExtractor} */ - protected ListenableFuture doExecute(URI url, HttpMethod method, AsyncRequestCallback requestCallback, - ResponseExtractor responseExtractor) throws RestClientException { + protected ListenableFuture doExecute(URI url, HttpMethod method, @Nullable AsyncRequestCallback requestCallback, + @Nullable ResponseExtractor responseExtractor) throws RestClientException { Assert.notNull(url, "'url' must not be null"); Assert.notNull(method, "'method' must not be null"); diff --git a/spring-web/src/main/java/org/springframework/web/client/DefaultResponseErrorHandler.java b/spring-web/src/main/java/org/springframework/web/client/DefaultResponseErrorHandler.java index 399187b46e..b5dfec7dcb 100644 --- a/spring-web/src/main/java/org/springframework/web/client/DefaultResponseErrorHandler.java +++ b/spring-web/src/main/java/org/springframework/web/client/DefaultResponseErrorHandler.java @@ -23,6 +23,7 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.client.ClientHttpResponse; +import org.springframework.lang.Nullable; import org.springframework.util.FileCopyUtils; /** @@ -110,6 +111,7 @@ public class DefaultResponseErrorHandler implements ResponseErrorHandler { * @return the associated charset, or {@code null} if none * @since 4.3.8 */ + @Nullable protected Charset getCharset(ClientHttpResponse response) { HttpHeaders headers = response.getHeaders(); MediaType contentType = headers.getContentType(); diff --git a/spring-web/src/main/java/org/springframework/web/client/HttpClientErrorException.java b/spring-web/src/main/java/org/springframework/web/client/HttpClientErrorException.java index 14883542a9..8e7814d21d 100644 --- a/spring-web/src/main/java/org/springframework/web/client/HttpClientErrorException.java +++ b/spring-web/src/main/java/org/springframework/web/client/HttpClientErrorException.java @@ -20,6 +20,7 @@ import java.nio.charset.Charset; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; +import org.springframework.lang.Nullable; /** * Exception thrown when an HTTP 4xx is received. @@ -61,7 +62,7 @@ public class HttpClientErrorException extends HttpStatusCodeException { * @param responseCharset the response body charset (may be {@code null}) */ public HttpClientErrorException(HttpStatus statusCode, String statusText, - byte[] responseBody, Charset responseCharset) { + @Nullable byte[] responseBody, @Nullable Charset responseCharset) { super(statusCode, statusText, responseBody, responseCharset); } @@ -77,7 +78,7 @@ public class HttpClientErrorException extends HttpStatusCodeException { * @since 3.1.2 */ public HttpClientErrorException(HttpStatus statusCode, String statusText, - HttpHeaders responseHeaders, byte[] responseBody, Charset responseCharset) { + @Nullable HttpHeaders responseHeaders, @Nullable byte[] responseBody, @Nullable Charset responseCharset) { super(statusCode, statusText, responseHeaders, responseBody, responseCharset); } diff --git a/spring-web/src/main/java/org/springframework/web/client/HttpServerErrorException.java b/spring-web/src/main/java/org/springframework/web/client/HttpServerErrorException.java index f4e494d931..128b371621 100644 --- a/spring-web/src/main/java/org/springframework/web/client/HttpServerErrorException.java +++ b/spring-web/src/main/java/org/springframework/web/client/HttpServerErrorException.java @@ -20,6 +20,7 @@ import java.nio.charset.Charset; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; +import org.springframework.lang.Nullable; /** * Exception thrown when an HTTP 5xx is received. @@ -62,7 +63,7 @@ public class HttpServerErrorException extends HttpStatusCodeException { * @since 3.0.5 */ public HttpServerErrorException(HttpStatus statusCode, String statusText, - byte[] responseBody, Charset responseCharset) { + @Nullable byte[] responseBody, @Nullable Charset responseCharset) { super(statusCode, statusText, responseBody, responseCharset); } @@ -78,7 +79,7 @@ public class HttpServerErrorException extends HttpStatusCodeException { * @since 3.1.2 */ public HttpServerErrorException(HttpStatus statusCode, String statusText, - HttpHeaders responseHeaders, byte[] responseBody, Charset responseCharset) { + @Nullable HttpHeaders responseHeaders, @Nullable byte[] responseBody, @Nullable Charset responseCharset) { super(statusCode, statusText, responseHeaders, responseBody, responseCharset); } diff --git a/spring-web/src/main/java/org/springframework/web/client/HttpStatusCodeException.java b/spring-web/src/main/java/org/springframework/web/client/HttpStatusCodeException.java index 0d5c2fbc19..a4f22478ed 100644 --- a/spring-web/src/main/java/org/springframework/web/client/HttpStatusCodeException.java +++ b/spring-web/src/main/java/org/springframework/web/client/HttpStatusCodeException.java @@ -20,6 +20,7 @@ import java.nio.charset.Charset; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; +import org.springframework.lang.Nullable; /** * Abstract base class for exceptions based on an {@link HttpStatus}. @@ -63,7 +64,7 @@ public abstract class HttpStatusCodeException extends RestClientResponseExceptio * @since 3.0.5 */ protected HttpStatusCodeException(HttpStatus statusCode, String statusText, - byte[] responseBody, Charset responseCharset) { + @Nullable byte[] responseBody, @Nullable Charset responseCharset) { this(statusCode, statusText, null, responseBody, responseCharset); } @@ -79,7 +80,7 @@ public abstract class HttpStatusCodeException extends RestClientResponseExceptio * @since 3.1.2 */ protected HttpStatusCodeException(HttpStatus statusCode, String statusText, - HttpHeaders responseHeaders, byte[] responseBody, Charset responseCharset) { + @Nullable HttpHeaders responseHeaders, @Nullable byte[] responseBody, @Nullable Charset responseCharset) { super(statusCode.value() + " " + statusText, statusCode.value(), statusText, responseHeaders, responseBody, responseCharset); diff --git a/spring-web/src/main/java/org/springframework/web/client/ResponseExtractor.java b/spring-web/src/main/java/org/springframework/web/client/ResponseExtractor.java index 143fb6925f..e77e6c91b1 100644 --- a/spring-web/src/main/java/org/springframework/web/client/ResponseExtractor.java +++ b/spring-web/src/main/java/org/springframework/web/client/ResponseExtractor.java @@ -19,6 +19,7 @@ package org.springframework.web.client; import java.io.IOException; import org.springframework.http.client.ClientHttpResponse; +import org.springframework.lang.Nullable; /** * Generic callback interface used by {@link RestTemplate}'s retrieval methods @@ -41,6 +42,7 @@ public interface ResponseExtractor { * @return the extracted data * @throws IOException in case of I/O errors */ + @Nullable T extractData(ClientHttpResponse response) throws IOException; } diff --git a/spring-web/src/main/java/org/springframework/web/client/RestClientResponseException.java b/spring-web/src/main/java/org/springframework/web/client/RestClientResponseException.java index d9c1e6a0f1..3779143280 100644 --- a/spring-web/src/main/java/org/springframework/web/client/RestClientResponseException.java +++ b/spring-web/src/main/java/org/springframework/web/client/RestClientResponseException.java @@ -20,6 +20,7 @@ import java.io.UnsupportedEncodingException; import java.nio.charset.Charset; import org.springframework.http.HttpHeaders; +import org.springframework.lang.Nullable; /** * Common base class for exceptions that contain actual HTTP response data. @@ -54,7 +55,7 @@ public class RestClientResponseException extends RestClientException { * @param responseCharset the response body charset (may be {@code null}) */ public RestClientResponseException(String message, int statusCode, String statusText, - HttpHeaders responseHeaders, byte[] responseBody, Charset responseCharset) { + @Nullable HttpHeaders responseHeaders, @Nullable byte[] responseBody, @Nullable Charset responseCharset) { super(message); this.rawStatusCode = statusCode; diff --git a/spring-web/src/main/java/org/springframework/web/client/RestOperations.java b/spring-web/src/main/java/org/springframework/web/client/RestOperations.java index aed0a89d10..4d93d9e659 100644 --- a/spring-web/src/main/java/org/springframework/web/client/RestOperations.java +++ b/spring-web/src/main/java/org/springframework/web/client/RestOperations.java @@ -26,6 +26,7 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.RequestEntity; import org.springframework.http.ResponseEntity; +import org.springframework.lang.Nullable; /** * Interface specifying a basic set of RESTful operations. @@ -51,6 +52,7 @@ public interface RestOperations { * @param uriVariables the variables to expand the template * @return the converted object */ + @Nullable T getForObject(String url, Class responseType, Object... uriVariables) throws RestClientException; /** @@ -62,6 +64,7 @@ public interface RestOperations { * @param uriVariables the map containing variables for the URI template * @return the converted object */ + @Nullable T getForObject(String url, Class responseType, Map uriVariables) throws RestClientException; /** @@ -71,6 +74,7 @@ public interface RestOperations { * @param responseType the type of the return value * @return the converted object */ + @Nullable T getForObject(URI url, Class responseType) throws RestClientException; /** @@ -150,7 +154,7 @@ public interface RestOperations { * @return the value for the {@code Location} header * @see HttpEntity */ - URI postForLocation(String url, Object request, Object... uriVariables) throws RestClientException; + URI postForLocation(String url, @Nullable Object request, Object... uriVariables) throws RestClientException; /** * Create a new resource by POSTing the given object to the URI template, and returns the value of @@ -164,7 +168,7 @@ public interface RestOperations { * @return the value for the {@code Location} header * @see HttpEntity */ - URI postForLocation(String url, Object request, Map uriVariables) throws RestClientException; + URI postForLocation(String url, @Nullable Object request, Map uriVariables) throws RestClientException; /** * Create a new resource by POSTing the given object to the URL, and returns the value of the @@ -176,7 +180,7 @@ public interface RestOperations { * @return the value for the {@code Location} header * @see HttpEntity */ - URI postForLocation(URI url, Object request) throws RestClientException; + URI postForLocation(URI url, @Nullable Object request) throws RestClientException; /** * Create a new resource by POSTing the given object to the URI template, @@ -191,7 +195,8 @@ public interface RestOperations { * @return the converted object * @see HttpEntity */ - T postForObject(String url, Object request, Class responseType, Object... uriVariables) + @Nullable + T postForObject(String url, @Nullable Object request, Class responseType, Object... uriVariables) throws RestClientException; /** @@ -207,7 +212,8 @@ public interface RestOperations { * @return the converted object * @see HttpEntity */ - T postForObject(String url, Object request, Class responseType, Map uriVariables) + @Nullable + T postForObject(String url, @Nullable Object request, Class responseType, Map uriVariables) throws RestClientException; /** @@ -221,7 +227,8 @@ public interface RestOperations { * @return the converted object * @see HttpEntity */ - T postForObject(URI url, Object request, Class responseType) throws RestClientException; + @Nullable + T postForObject(URI url, @Nullable Object request, Class responseType) throws RestClientException; /** * Create a new resource by POSTing the given object to the URI template, @@ -236,7 +243,7 @@ public interface RestOperations { * @since 3.0.2 * @see HttpEntity */ - ResponseEntity postForEntity(String url, Object request, Class responseType, Object... uriVariables) + ResponseEntity postForEntity(String url, @Nullable Object request, Class responseType, Object... uriVariables) throws RestClientException; /** @@ -252,7 +259,7 @@ public interface RestOperations { * @since 3.0.2 * @see HttpEntity */ - ResponseEntity postForEntity(String url, Object request, Class responseType, Map uriVariables) + ResponseEntity postForEntity(String url, @Nullable Object request, Class responseType, Map uriVariables) throws RestClientException; /** @@ -266,7 +273,7 @@ public interface RestOperations { * @since 3.0.2 * @see HttpEntity */ - ResponseEntity postForEntity(URI url, Object request, Class responseType) throws RestClientException; + ResponseEntity postForEntity(URI url, @Nullable Object request, Class responseType) throws RestClientException; // PUT @@ -281,7 +288,7 @@ public interface RestOperations { * @param uriVariables the variables to expand the template * @see HttpEntity */ - void put(String url, Object request, Object... uriVariables) throws RestClientException; + void put(String url, @Nullable Object request, Object... uriVariables) throws RestClientException; /** * Creates a new resource by PUTting the given object to URI template. @@ -293,7 +300,7 @@ public interface RestOperations { * @param uriVariables the variables to expand the template * @see HttpEntity */ - void put(String url, Object request, Map uriVariables) throws RestClientException; + void put(String url, @Nullable Object request, Map uriVariables) throws RestClientException; /** * Creates a new resource by PUTting the given object to URL. @@ -303,7 +310,7 @@ public interface RestOperations { * @param request the Object to be PUT (may be {@code null}) * @see HttpEntity */ - void put(URI url, Object request) throws RestClientException; + void put(URI url, @Nullable Object request) throws RestClientException; // PATCH @@ -327,7 +334,8 @@ public interface RestOperations { * @see org.springframework.http.client.HttpComponentsAsyncClientHttpRequestFactory * @see org.springframework.http.client.OkHttp3ClientHttpRequestFactory */ - T patchForObject(String url, Object request, Class responseType, Object... uriVariables) + @Nullable + T patchForObject(String url, @Nullable Object request, Class responseType, Object... uriVariables) throws RestClientException; /** @@ -349,7 +357,8 @@ public interface RestOperations { * @see org.springframework.http.client.HttpComponentsAsyncClientHttpRequestFactory * @see org.springframework.http.client.OkHttp3ClientHttpRequestFactory */ - T patchForObject(String url, Object request, Class responseType, Map uriVariables) + @Nullable + T patchForObject(String url, @Nullable Object request, Class responseType, Map uriVariables) throws RestClientException; /** @@ -369,7 +378,8 @@ public interface RestOperations { * @see org.springframework.http.client.HttpComponentsAsyncClientHttpRequestFactory * @see org.springframework.http.client.OkHttp3ClientHttpRequestFactory */ - T patchForObject(URI url, Object request, Class responseType) throws RestClientException; + @Nullable + T patchForObject(URI url, @Nullable Object request, Class responseType) throws RestClientException; @@ -442,7 +452,7 @@ public interface RestOperations { * @return the response as entity * @since 3.0.2 */ - ResponseEntity exchange(String url, HttpMethod method, HttpEntity requestEntity, + ResponseEntity exchange(String url, HttpMethod method, @Nullable HttpEntity requestEntity, Class responseType, Object... uriVariables) throws RestClientException; /** @@ -458,7 +468,7 @@ public interface RestOperations { * @return the response as entity * @since 3.0.2 */ - ResponseEntity exchange(String url, HttpMethod method, HttpEntity requestEntity, + ResponseEntity exchange(String url, HttpMethod method, @Nullable HttpEntity requestEntity, Class responseType, Map uriVariables) throws RestClientException; /** @@ -472,7 +482,7 @@ public interface RestOperations { * @return the response as entity * @since 3.0.2 */ - ResponseEntity exchange(URI url, HttpMethod method, HttpEntity requestEntity, + ResponseEntity exchange(URI url, HttpMethod method, @Nullable HttpEntity requestEntity, Class responseType) throws RestClientException; /** @@ -492,7 +502,7 @@ public interface RestOperations { * @return the response as entity * @since 3.2 */ - ResponseEntity exchange(String url,HttpMethod method, HttpEntity requestEntity, + ResponseEntity exchange(String url,HttpMethod method, @Nullable HttpEntity requestEntity, ParameterizedTypeReference responseType, Object... uriVariables) throws RestClientException; /** @@ -512,7 +522,7 @@ public interface RestOperations { * @return the response as entity * @since 3.2 */ - ResponseEntity exchange(String url, HttpMethod method, HttpEntity requestEntity, + ResponseEntity exchange(String url, HttpMethod method, @Nullable HttpEntity requestEntity, ParameterizedTypeReference responseType, Map uriVariables) throws RestClientException; /** @@ -531,7 +541,7 @@ public interface RestOperations { * @return the response as entity * @since 3.2 */ - ResponseEntity exchange(URI url, HttpMethod method, HttpEntity requestEntity, + ResponseEntity exchange(URI url, HttpMethod method, @Nullable HttpEntity requestEntity, ParameterizedTypeReference responseType) throws RestClientException; /** @@ -582,6 +592,7 @@ public interface RestOperations { * @param uriVariables the variables to expand in the template * @return an arbitrary object, as returned by the {@link ResponseExtractor} */ + @Nullable T execute(String url, HttpMethod method, RequestCallback requestCallback, ResponseExtractor responseExtractor, Object... uriVariables) throws RestClientException; @@ -596,6 +607,7 @@ public interface RestOperations { * @param uriVariables the variables to expand in the template * @return an arbitrary object, as returned by the {@link ResponseExtractor} */ + @Nullable T execute(String url, HttpMethod method, RequestCallback requestCallback, ResponseExtractor responseExtractor, Map uriVariables) throws RestClientException; @@ -608,6 +620,7 @@ public interface RestOperations { * @param responseExtractor object that extracts the return value from the response * @return an arbitrary object, as returned by the {@link ResponseExtractor} */ + @Nullable T execute(URI url, HttpMethod method, RequestCallback requestCallback, ResponseExtractor responseExtractor) throws RestClientException; diff --git a/spring-web/src/main/java/org/springframework/web/client/RestTemplate.java b/spring-web/src/main/java/org/springframework/web/client/RestTemplate.java index dfe291f241..eac4ddfb05 100644 --- a/spring-web/src/main/java/org/springframework/web/client/RestTemplate.java +++ b/spring-web/src/main/java/org/springframework/web/client/RestTemplate.java @@ -51,6 +51,7 @@ import org.springframework.http.converter.support.AllEncompassingFormHttpMessage import org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter; import org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter; import org.springframework.http.converter.xml.SourceHttpMessageConverter; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.web.util.DefaultUriBuilderFactory; @@ -667,8 +668,9 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat * @param responseExtractor object that extracts the return value from the response (can be {@code null}) * @return an arbitrary object, as returned by the {@link ResponseExtractor} */ - protected T doExecute(URI url, HttpMethod method, RequestCallback requestCallback, - ResponseExtractor responseExtractor) throws RestClientException { + @Nullable + protected T doExecute(URI url, HttpMethod method, @Nullable RequestCallback requestCallback, + @Nullable ResponseExtractor responseExtractor) throws RestClientException { Assert.notNull(url, "'url' must not be null"); Assert.notNull(method, "'method' must not be null"); diff --git a/spring-web/src/main/java/org/springframework/web/client/UnknownHttpStatusCodeException.java b/spring-web/src/main/java/org/springframework/web/client/UnknownHttpStatusCodeException.java index b8e894b925..9b01977052 100644 --- a/spring-web/src/main/java/org/springframework/web/client/UnknownHttpStatusCodeException.java +++ b/spring-web/src/main/java/org/springframework/web/client/UnknownHttpStatusCodeException.java @@ -20,6 +20,7 @@ import java.nio.charset.Charset; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; +import org.springframework.lang.Nullable; /** * Exception thrown when an unknown (or custom) HTTP status code is received. @@ -42,7 +43,7 @@ public class UnknownHttpStatusCodeException extends RestClientResponseException * @param responseCharset the response body charset, may be {@code null} */ public UnknownHttpStatusCodeException(int rawStatusCode, String statusText, - HttpHeaders responseHeaders, byte[] responseBody, Charset responseCharset) { + @Nullable HttpHeaders responseHeaders, @Nullable byte[] responseBody,@Nullable Charset responseCharset) { super("Unknown status code [" + String.valueOf(rawStatusCode) + "]" + " " + statusText, rawStatusCode, statusText, responseHeaders, responseBody, responseCharset); diff --git a/spring-web/src/main/java/org/springframework/web/client/package-info.java b/spring-web/src/main/java/org/springframework/web/client/package-info.java index c4de044765..56cccb4c7e 100644 --- a/spring-web/src/main/java/org/springframework/web/client/package-info.java +++ b/spring-web/src/main/java/org/springframework/web/client/package-info.java @@ -2,4 +2,7 @@ * Core package of the client-side web support. * Provides a RestTemplate class and various callback interfaces. */ +@NonNullApi package org.springframework.web.client; + +import org.springframework.lang.NonNullApi; diff --git a/spring-web/src/main/java/org/springframework/web/client/support/package-info.java b/spring-web/src/main/java/org/springframework/web/client/support/package-info.java index d7fd057b31..b617229b2d 100644 --- a/spring-web/src/main/java/org/springframework/web/client/support/package-info.java +++ b/spring-web/src/main/java/org/springframework/web/client/support/package-info.java @@ -2,4 +2,7 @@ * Classes supporting the {@code org.springframework.web.client} package. * Contains a base class for RestTemplate usage. */ +@NonNullApi package org.springframework.web.client.support; + +import org.springframework.lang.NonNullApi; diff --git a/spring-web/src/main/java/org/springframework/web/context/AbstractContextLoaderInitializer.java b/spring-web/src/main/java/org/springframework/web/context/AbstractContextLoaderInitializer.java index 49622568bd..7e56d42879 100644 --- a/spring-web/src/main/java/org/springframework/web/context/AbstractContextLoaderInitializer.java +++ b/spring-web/src/main/java/org/springframework/web/context/AbstractContextLoaderInitializer.java @@ -23,6 +23,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.context.ApplicationContextInitializer; +import org.springframework.lang.Nullable; import org.springframework.web.WebApplicationInitializer; /** @@ -79,6 +80,7 @@ public abstract class AbstractContextLoaderInitializer implements WebApplication * desired * @see org.springframework.web.servlet.support.AbstractDispatcherServletInitializer */ + @Nullable protected abstract WebApplicationContext createRootApplicationContext(); /** @@ -88,6 +90,7 @@ public abstract class AbstractContextLoaderInitializer implements WebApplication * @see #createRootApplicationContext() * @see ContextLoaderListener#setContextInitializers */ + @Nullable protected ApplicationContextInitializer[] getRootApplicationContextInitializers() { return null; } diff --git a/spring-web/src/main/java/org/springframework/web/context/ConfigurableWebApplicationContext.java b/spring-web/src/main/java/org/springframework/web/context/ConfigurableWebApplicationContext.java index a48338358b..9d101a5472 100644 --- a/spring-web/src/main/java/org/springframework/web/context/ConfigurableWebApplicationContext.java +++ b/spring-web/src/main/java/org/springframework/web/context/ConfigurableWebApplicationContext.java @@ -20,6 +20,7 @@ import javax.servlet.ServletConfig; import javax.servlet.ServletContext; import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.lang.Nullable; /** * Interface to be implemented by configurable web application contexts. @@ -69,6 +70,7 @@ public interface ConfigurableWebApplicationContext extends WebApplicationContext /** * Return the ServletConfig for this web application context, if any. */ + @Nullable ServletConfig getServletConfig(); /** @@ -81,6 +83,7 @@ public interface ConfigurableWebApplicationContext extends WebApplicationContext /** * Return the namespace for this web application context, if any. */ + @Nullable String getNamespace(); /** @@ -102,6 +105,7 @@ public interface ConfigurableWebApplicationContext extends WebApplicationContext * Return the config locations for this web application context, * or {@code null} if none specified. */ + @Nullable String[] getConfigLocations(); } diff --git a/spring-web/src/main/java/org/springframework/web/context/ConfigurableWebEnvironment.java b/spring-web/src/main/java/org/springframework/web/context/ConfigurableWebEnvironment.java index 241f102319..f2a6788405 100644 --- a/spring-web/src/main/java/org/springframework/web/context/ConfigurableWebEnvironment.java +++ b/spring-web/src/main/java/org/springframework/web/context/ConfigurableWebEnvironment.java @@ -20,6 +20,7 @@ import javax.servlet.ServletConfig; import javax.servlet.ServletContext; import org.springframework.core.env.ConfigurableEnvironment; +import org.springframework.lang.Nullable; /** * Specialization of {@link ConfigurableEnvironment} allowing initialization of @@ -43,6 +44,6 @@ public interface ConfigurableWebEnvironment extends ConfigurableEnvironment { * @see org.springframework.web.context.support.WebApplicationContextUtils#initServletPropertySources( * org.springframework.core.env.MutablePropertySources, ServletContext, ServletConfig) */ - void initPropertySources(ServletContext servletContext, ServletConfig servletConfig); + void initPropertySources(@Nullable ServletContext servletContext, @Nullable ServletConfig servletConfig); } diff --git a/spring-web/src/main/java/org/springframework/web/context/ContextLoader.java b/spring-web/src/main/java/org/springframework/web/context/ContextLoader.java index 85204e96b4..b8edf4b091 100644 --- a/spring-web/src/main/java/org/springframework/web/context/ContextLoader.java +++ b/spring-web/src/main/java/org/springframework/web/context/ContextLoader.java @@ -22,6 +22,7 @@ import java.util.List; import java.util.Map; import java.util.Properties; import java.util.concurrent.ConcurrentHashMap; + import javax.servlet.ServletContext; import org.apache.commons.logging.Log; @@ -37,6 +38,7 @@ import org.springframework.core.annotation.AnnotationAwareOrderComparator; import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.support.PropertiesLoaderUtils; +import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; @@ -504,6 +506,7 @@ public class ContextLoader { * @param servletContext current servlet context * @return the parent application context, or {@code null} if none */ + @Nullable protected ApplicationContext loadParentContext(ServletContext servletContext) { return null; } @@ -542,6 +545,7 @@ public class ContextLoader { * if none found * @see org.springframework.web.context.support.SpringBeanAutowiringSupport */ + @Nullable public static WebApplicationContext getCurrentWebApplicationContext() { ClassLoader ccl = Thread.currentThread().getContextClassLoader(); if (ccl != null) { diff --git a/spring-web/src/main/java/org/springframework/web/context/annotation/package-info.java b/spring-web/src/main/java/org/springframework/web/context/annotation/package-info.java index fffce1b058..b56cc70a48 100644 --- a/spring-web/src/main/java/org/springframework/web/context/annotation/package-info.java +++ b/spring-web/src/main/java/org/springframework/web/context/annotation/package-info.java @@ -1,4 +1,7 @@ /** * Provides convenience annotations for web scopes. */ +@NonNullApi package org.springframework.web.context.annotation; + +import org.springframework.lang.NonNullApi; diff --git a/spring-web/src/main/java/org/springframework/web/context/package-info.java b/spring-web/src/main/java/org/springframework/web/context/package-info.java index 2cc6192a80..b00b31383a 100644 --- a/spring-web/src/main/java/org/springframework/web/context/package-info.java +++ b/spring-web/src/main/java/org/springframework/web/context/package-info.java @@ -2,4 +2,7 @@ * Contains a variant of the application context interface for web applications, * and the ContextLoaderListener that bootstraps a root web application context. */ +@NonNullApi package org.springframework.web.context; + +import org.springframework.lang.NonNullApi; diff --git a/spring-web/src/main/java/org/springframework/web/context/request/NativeWebRequest.java b/spring-web/src/main/java/org/springframework/web/context/request/NativeWebRequest.java index edf161e127..79b6f9b4c2 100644 --- a/spring-web/src/main/java/org/springframework/web/context/request/NativeWebRequest.java +++ b/spring-web/src/main/java/org/springframework/web/context/request/NativeWebRequest.java @@ -16,6 +16,8 @@ package org.springframework.web.context.request; +import org.springframework.lang.Nullable; + /** * Extension of the {@link WebRequest} interface, exposing the * native request and response objects in a generic fashion. @@ -47,6 +49,7 @@ public interface NativeWebRequest extends WebRequest { * of that type is available * @see javax.servlet.http.HttpServletRequest */ + @Nullable T getNativeRequest(Class requiredType); /** @@ -56,6 +59,7 @@ public interface NativeWebRequest extends WebRequest { * of that type is available * @see javax.servlet.http.HttpServletResponse */ + @Nullable T getNativeResponse(Class requiredType); } diff --git a/spring-web/src/main/java/org/springframework/web/context/request/RequestAttributes.java b/spring-web/src/main/java/org/springframework/web/context/request/RequestAttributes.java index 6fba81f3c2..fd92841199 100644 --- a/spring-web/src/main/java/org/springframework/web/context/request/RequestAttributes.java +++ b/spring-web/src/main/java/org/springframework/web/context/request/RequestAttributes.java @@ -16,6 +16,8 @@ package org.springframework.web.context.request; +import org.springframework.lang.Nullable; + /** * Abstraction for accessing attribute objects associated with a request. * Supports access to request-scoped attributes as well as to session-scoped @@ -63,6 +65,7 @@ public interface RequestAttributes { * @param scope the scope identifier * @return the current attribute value, or {@code null} if not found */ + @Nullable Object getAttribute(String name, int scope); /** @@ -122,12 +125,14 @@ public interface RequestAttributes { * @param key the contextual key * @return the corresponding object, or {@code null} if none found */ + @Nullable Object resolveReference(String key); /** * Return an id for the current underlying session. * @return the session id as String (never {@code null}) */ + @Nullable String getSessionId(); /** @@ -135,6 +140,7 @@ public interface RequestAttributes { * that is, an object to synchronize on for the underlying session. * @return the session mutex to use (never {@code null}) */ + @Nullable Object getSessionMutex(); } diff --git a/spring-web/src/main/java/org/springframework/web/context/request/RequestContextHolder.java b/spring-web/src/main/java/org/springframework/web/context/request/RequestContextHolder.java index 365f66f6c4..6a7a1e4fdd 100644 --- a/spring-web/src/main/java/org/springframework/web/context/request/RequestContextHolder.java +++ b/spring-web/src/main/java/org/springframework/web/context/request/RequestContextHolder.java @@ -20,6 +20,7 @@ import javax.faces.context.FacesContext; import org.springframework.core.NamedInheritableThreadLocal; import org.springframework.core.NamedThreadLocal; +import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; /** @@ -78,7 +79,7 @@ public abstract class RequestContextHolder { * @param inheritable whether to expose the RequestAttributes as inheritable * for child threads (using an {@link InheritableThreadLocal}) */ - public static void setRequestAttributes(RequestAttributes attributes, boolean inheritable) { + public static void setRequestAttributes(@Nullable RequestAttributes attributes, boolean inheritable) { if (attributes == null) { resetRequestAttributes(); } @@ -99,6 +100,7 @@ public abstract class RequestContextHolder { * @return the RequestAttributes currently bound to the thread, * or {@code null} if none bound */ + @Nullable public static RequestAttributes getRequestAttributes() { RequestAttributes attributes = requestAttributesHolder.get(); if (attributes == null) { diff --git a/spring-web/src/main/java/org/springframework/web/context/request/ServletRequestAttributes.java b/spring-web/src/main/java/org/springframework/web/context/request/ServletRequestAttributes.java index 970c77b755..b57eff81e6 100644 --- a/spring-web/src/main/java/org/springframework/web/context/request/ServletRequestAttributes.java +++ b/spring-web/src/main/java/org/springframework/web/context/request/ServletRequestAttributes.java @@ -24,6 +24,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.NumberUtils; import org.springframework.util.StringUtils; @@ -98,6 +99,7 @@ public class ServletRequestAttributes extends AbstractRequestAttributes { /** * Exposes the native {@link HttpServletResponse} that we're wrapping (if any). */ + @Nullable public final HttpServletResponse getResponse() { return this.response; } diff --git a/spring-web/src/main/java/org/springframework/web/context/request/WebRequest.java b/spring-web/src/main/java/org/springframework/web/context/request/WebRequest.java index c4c11eb487..1db8b9735b 100644 --- a/spring-web/src/main/java/org/springframework/web/context/request/WebRequest.java +++ b/spring-web/src/main/java/org/springframework/web/context/request/WebRequest.java @@ -21,6 +21,8 @@ import java.util.Iterator; import java.util.Locale; import java.util.Map; +import org.springframework.lang.Nullable; + /** * Generic interface for a web request. Mainly intended for generic web * request interceptors, giving them access to general request metadata, @@ -39,6 +41,7 @@ public interface WebRequest extends RequestAttributes { * @since 3.0 * @see javax.servlet.http.HttpServletRequest#getHeader(String) */ + @Nullable String getHeader(String headerName); /** @@ -48,6 +51,7 @@ public interface WebRequest extends RequestAttributes { * @since 3.0 * @see javax.servlet.http.HttpServletRequest#getHeaders(String) */ + @Nullable String[] getHeaderValues(String headerName); /** @@ -62,6 +66,7 @@ public interface WebRequest extends RequestAttributes { *

    Retrieves the first parameter value in case of a multi-value parameter. * @see javax.servlet.http.HttpServletRequest#getParameter(String) */ + @Nullable String getParameter(String paramName); /** @@ -70,6 +75,7 @@ public interface WebRequest extends RequestAttributes { *

    A single-value parameter will be exposed as an array with a single element. * @see javax.servlet.http.HttpServletRequest#getParameterValues(String) */ + @Nullable String[] getParameterValues(String paramName); /** @@ -104,12 +110,14 @@ public interface WebRequest extends RequestAttributes { * Return the remote user for this request, if any. * @see javax.servlet.http.HttpServletRequest#getRemoteUser() */ + @Nullable String getRemoteUser(); /** * Return the user principal for this request, if any. * @see javax.servlet.http.HttpServletRequest#getUserPrincipal() */ + @Nullable Principal getUserPrincipal(); /** diff --git a/spring-web/src/main/java/org/springframework/web/context/request/WebRequestInterceptor.java b/spring-web/src/main/java/org/springframework/web/context/request/WebRequestInterceptor.java index 4b16c98334..aee6209a4e 100644 --- a/spring-web/src/main/java/org/springframework/web/context/request/WebRequestInterceptor.java +++ b/spring-web/src/main/java/org/springframework/web/context/request/WebRequestInterceptor.java @@ -16,6 +16,7 @@ package org.springframework.web.context.request; +import org.springframework.lang.Nullable; import org.springframework.ui.ModelMap; /** @@ -75,7 +76,7 @@ public interface WebRequestInterceptor { * and/or to add further model attributes, if desired. * @throws Exception in case of errors */ - void postHandle(WebRequest request, ModelMap model) throws Exception; + void postHandle(WebRequest request, @Nullable ModelMap model) throws Exception; /** * Callback after completion of request processing, that is, after rendering @@ -87,6 +88,6 @@ public interface WebRequestInterceptor { * @param ex exception thrown on handler execution, if any * @throws Exception in case of errors */ - void afterCompletion(WebRequest request, Exception ex) throws Exception; + void afterCompletion(WebRequest request, @Nullable Exception ex) throws Exception; } diff --git a/spring-web/src/main/java/org/springframework/web/context/request/async/AsyncWebRequest.java b/spring-web/src/main/java/org/springframework/web/context/request/async/AsyncWebRequest.java index 529e664422..64c8072ccc 100644 --- a/spring-web/src/main/java/org/springframework/web/context/request/async/AsyncWebRequest.java +++ b/spring-web/src/main/java/org/springframework/web/context/request/async/AsyncWebRequest.java @@ -16,6 +16,7 @@ package org.springframework.web.context.request.async; +import org.springframework.lang.Nullable; import org.springframework.web.context.request.NativeWebRequest; /** @@ -33,7 +34,7 @@ public interface AsyncWebRequest extends NativeWebRequest { * @param timeout amount of time in milliseconds; {@code null} means no * timeout, i.e. rely on the default timeout of the container. */ - void setTimeout(Long timeout); + void setTimeout(@Nullable Long timeout); /** * Add a handler to invoke when concurrent handling has timed out. diff --git a/spring-web/src/main/java/org/springframework/web/context/request/async/DeferredResult.java b/spring-web/src/main/java/org/springframework/web/context/request/async/DeferredResult.java index e2ad4be263..5d65839b35 100644 --- a/spring-web/src/main/java/org/springframework/web/context/request/async/DeferredResult.java +++ b/spring-web/src/main/java/org/springframework/web/context/request/async/DeferredResult.java @@ -22,6 +22,7 @@ import java.util.concurrent.Callable; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.context.request.NativeWebRequest; @@ -93,7 +94,7 @@ public class DeferredResult { * @param timeout timeout value in milliseconds (ignored if {@code null}) * @param timeoutResult the result to use */ - public DeferredResult(Long timeout, Object timeoutResult) { + public DeferredResult(@Nullable Long timeout, Object timeoutResult) { this.timeoutResult = timeoutResult; this.timeout = timeout; } @@ -125,6 +126,7 @@ public class DeferredResult { * to check if there is a result prior to calling this method. * @since 4.0 */ + @Nullable public Object getResult() { Object resultToCheck = this.result; return (resultToCheck != RESULT_NONE ? resultToCheck : null); diff --git a/spring-web/src/main/java/org/springframework/web/context/request/async/WebAsyncManager.java b/spring-web/src/main/java/org/springframework/web/context/request/async/WebAsyncManager.java index 5054041431..aaf53a27a7 100644 --- a/spring-web/src/main/java/org/springframework/web/context/request/async/WebAsyncManager.java +++ b/spring-web/src/main/java/org/springframework/web/context/request/async/WebAsyncManager.java @@ -22,6 +22,7 @@ import java.util.List; import java.util.Map; import java.util.concurrent.Callable; import java.util.concurrent.RejectedExecutionException; + import javax.servlet.http.HttpServletRequest; import org.apache.commons.logging.Log; @@ -29,6 +30,7 @@ import org.apache.commons.logging.LogFactory; import org.springframework.core.task.AsyncTaskExecutor; import org.springframework.core.task.SimpleAsyncTaskExecutor; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.context.request.RequestAttributes; import org.springframework.web.context.request.async.DeferredResult.DeferredResultHandler; @@ -166,6 +168,7 @@ public final class WebAsyncManager { * @param key the key * @return the interceptor registered under that key or {@code null} */ + @Nullable public CallableProcessingInterceptor getCallableInterceptor(Object key) { return this.callableInterceptors.get(key); } @@ -175,6 +178,7 @@ public final class WebAsyncManager { * @param key the key * @return the interceptor registered under that key or {@code null} */ + @Nullable public DeferredResultProcessingInterceptor getDeferredResultInterceptor(Object key) { return this.deferredResultInterceptors.get(key); } diff --git a/spring-web/src/main/java/org/springframework/web/context/request/async/WebAsyncTask.java b/spring-web/src/main/java/org/springframework/web/context/request/async/WebAsyncTask.java index 21a4ede67f..002c1d602d 100644 --- a/spring-web/src/main/java/org/springframework/web/context/request/async/WebAsyncTask.java +++ b/spring-web/src/main/java/org/springframework/web/context/request/async/WebAsyncTask.java @@ -21,6 +21,7 @@ import java.util.concurrent.Callable; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.core.task.AsyncTaskExecutor; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.context.request.NativeWebRequest; @@ -73,7 +74,7 @@ public class WebAsyncTask implements BeanFactoryAware { * @param executorName the name of an executor bean to use * @param callable the callable for concurrent handling */ - public WebAsyncTask(Long timeout, String executorName, Callable callable) { + public WebAsyncTask(@Nullable Long timeout, String executorName, Callable callable) { this(callable); Assert.notNull(executorName, "Executor name must not be null"); this.executorName = executorName; @@ -86,7 +87,7 @@ public class WebAsyncTask implements BeanFactoryAware { * @param executor the executor to use * @param callable the callable for concurrent handling */ - public WebAsyncTask(Long timeout, AsyncTaskExecutor executor, Callable callable) { + public WebAsyncTask(@Nullable Long timeout, AsyncTaskExecutor executor, Callable callable) { this(callable); Assert.notNull(executor, "Executor must not be null"); this.executor = executor; @@ -104,6 +105,7 @@ public class WebAsyncTask implements BeanFactoryAware { /** * Return the timeout value in milliseconds, or {@code null} if no timeout is set. */ + @Nullable public Long getTimeout() { return this.timeout; } @@ -121,6 +123,7 @@ public class WebAsyncTask implements BeanFactoryAware { * Return the AsyncTaskExecutor to use for concurrent handling, * or {@code null} if none specified. */ + @Nullable public AsyncTaskExecutor getExecutor() { if (this.executor != null) { return this.executor; diff --git a/spring-web/src/main/java/org/springframework/web/context/request/package-info.java b/spring-web/src/main/java/org/springframework/web/context/request/package-info.java index 30f66417cd..2606643808 100644 --- a/spring-web/src/main/java/org/springframework/web/context/request/package-info.java +++ b/spring-web/src/main/java/org/springframework/web/context/request/package-info.java @@ -2,4 +2,7 @@ * Support for generic request context holding, in particular for * scoping of application objects per HTTP request or HTTP session. */ +@NonNullApi package org.springframework.web.context.request; + +import org.springframework.lang.NonNullApi; diff --git a/spring-web/src/main/java/org/springframework/web/context/support/AnnotationConfigWebApplicationContext.java b/spring-web/src/main/java/org/springframework/web/context/support/AnnotationConfigWebApplicationContext.java index ceb2c2ede6..a64dd3f1cf 100644 --- a/spring-web/src/main/java/org/springframework/web/context/support/AnnotationConfigWebApplicationContext.java +++ b/spring-web/src/main/java/org/springframework/web/context/support/AnnotationConfigWebApplicationContext.java @@ -27,6 +27,7 @@ import org.springframework.context.annotation.AnnotationConfigRegistry; import org.springframework.context.annotation.AnnotationConfigUtils; import org.springframework.context.annotation.ClassPathBeanDefinitionScanner; import org.springframework.context.annotation.ScopeMetadataResolver; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.StringUtils; import org.springframework.web.context.ContextLoader; @@ -106,6 +107,7 @@ public class AnnotationConfigWebApplicationContext extends AbstractRefreshableWe * Return the custom {@link BeanNameGenerator} for use with {@link AnnotatedBeanDefinitionReader} * and/or {@link ClassPathBeanDefinitionScanner}, if any. */ + @Nullable protected BeanNameGenerator getBeanNameGenerator() { return this.beanNameGenerator; } @@ -125,6 +127,7 @@ public class AnnotationConfigWebApplicationContext extends AbstractRefreshableWe * Return the custom {@link ScopeMetadataResolver} for use with {@link AnnotatedBeanDefinitionReader} * and/or {@link ClassPathBeanDefinitionScanner}, if any. */ + @Nullable protected ScopeMetadataResolver getScopeMetadataResolver() { return this.scopeMetadataResolver; } diff --git a/spring-web/src/main/java/org/springframework/web/context/support/RequestHandledEvent.java b/spring-web/src/main/java/org/springframework/web/context/support/RequestHandledEvent.java index 343aad71c5..bbb3ce7ff3 100644 --- a/spring-web/src/main/java/org/springframework/web/context/support/RequestHandledEvent.java +++ b/spring-web/src/main/java/org/springframework/web/context/support/RequestHandledEvent.java @@ -17,6 +17,7 @@ package org.springframework.web.context.support; import org.springframework.context.ApplicationEvent; +import org.springframework.lang.Nullable; /** * Event raised when a request is handled within an ApplicationContext. @@ -57,7 +58,7 @@ public class RequestHandledEvent extends ApplicationEvent { * request, if any (usually the UserPrincipal) * @param processingTimeMillis the processing time of the request in milliseconds */ - public RequestHandledEvent(Object source, String sessionId, String userName, long processingTimeMillis) { + public RequestHandledEvent(Object source, @Nullable String sessionId, @Nullable String userName, long processingTimeMillis) { super(source); this.sessionId = sessionId; this.userName = userName; @@ -74,7 +75,7 @@ public class RequestHandledEvent extends ApplicationEvent { * @param failureCause the cause of failure, if any */ public RequestHandledEvent( - Object source, String sessionId, String userName, long processingTimeMillis, Throwable failureCause) { + Object source, @Nullable String sessionId, @Nullable String userName, long processingTimeMillis, @Nullable Throwable failureCause) { this(source, sessionId, userName, processingTimeMillis); this.failureCause = failureCause; @@ -91,6 +92,7 @@ public class RequestHandledEvent extends ApplicationEvent { /** * Return the id of the HTTP session, if any. */ + @Nullable public String getSessionId() { return this.sessionId; } @@ -100,6 +102,7 @@ public class RequestHandledEvent extends ApplicationEvent { * (usually the UserPrincipal). * @see javax.servlet.http.HttpServletRequest#getUserPrincipal() */ + @Nullable public String getUserName() { return this.userName; } @@ -114,6 +117,7 @@ public class RequestHandledEvent extends ApplicationEvent { /** * Return the cause of failure, if any. */ + @Nullable public Throwable getFailureCause() { return this.failureCause; } diff --git a/spring-web/src/main/java/org/springframework/web/context/support/ServletContextAwareProcessor.java b/spring-web/src/main/java/org/springframework/web/context/support/ServletContextAwareProcessor.java index b20a79fe73..5ad591a216 100644 --- a/spring-web/src/main/java/org/springframework/web/context/support/ServletContextAwareProcessor.java +++ b/spring-web/src/main/java/org/springframework/web/context/support/ServletContextAwareProcessor.java @@ -21,6 +21,7 @@ import javax.servlet.ServletContext; import org.springframework.beans.BeansException; import org.springframework.beans.factory.config.BeanPostProcessor; +import org.springframework.lang.Nullable; import org.springframework.web.context.ServletConfigAware; import org.springframework.web.context.ServletContextAware; @@ -81,6 +82,7 @@ public class ServletContextAwareProcessor implements BeanPostProcessor { * can be overridden by subclasses when a context is obtained after the post-processor * has been registered. */ + @Nullable protected ServletContext getServletContext() { if (this.servletContext == null && getServletConfig() != null) { return getServletConfig().getServletContext(); @@ -89,10 +91,11 @@ public class ServletContextAwareProcessor implements BeanPostProcessor { } /** - * Returns the {@link ServletContext} to be injected or {@code null}. This method + * Returns the {@link ServletConfig} to be injected or {@code null}. This method * can be overridden by subclasses when a context is obtained after the post-processor * has been registered. */ + @Nullable protected ServletConfig getServletConfig() { return this.servletConfig; } diff --git a/spring-web/src/main/java/org/springframework/web/context/support/ServletContextResource.java b/spring-web/src/main/java/org/springframework/web/context/support/ServletContextResource.java index 916a4c1194..758c2755f5 100644 --- a/spring-web/src/main/java/org/springframework/web/context/support/ServletContextResource.java +++ b/spring-web/src/main/java/org/springframework/web/context/support/ServletContextResource.java @@ -22,6 +22,7 @@ import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; + import javax.servlet.ServletContext; import org.springframework.core.io.AbstractFileResolvingResource; diff --git a/spring-web/src/main/java/org/springframework/web/context/support/ServletRequestHandledEvent.java b/spring-web/src/main/java/org/springframework/web/context/support/ServletRequestHandledEvent.java index c08405a7cc..d6c36f0170 100644 --- a/spring-web/src/main/java/org/springframework/web/context/support/ServletRequestHandledEvent.java +++ b/spring-web/src/main/java/org/springframework/web/context/support/ServletRequestHandledEvent.java @@ -16,6 +16,8 @@ package org.springframework.web.context.support; +import org.springframework.lang.Nullable; + /** * Servlet-specific subclass of RequestHandledEvent, * adding servlet-specific context information. @@ -58,7 +60,7 @@ public class ServletRequestHandledEvent extends RequestHandledEvent { */ public ServletRequestHandledEvent(Object source, String requestUrl, String clientAddress, String method, String servletName, - String sessionId, String userName, long processingTimeMillis) { + @Nullable String sessionId, @Nullable String userName, long processingTimeMillis) { super(source, sessionId, userName, processingTimeMillis); this.requestUrl = requestUrl; @@ -82,8 +84,8 @@ public class ServletRequestHandledEvent extends RequestHandledEvent { * @param failureCause the cause of failure, if any */ public ServletRequestHandledEvent(Object source, String requestUrl, - String clientAddress, String method, String servletName, String sessionId, - String userName, long processingTimeMillis, Throwable failureCause) { + String clientAddress, String method, String servletName, @Nullable String sessionId, + @Nullable String userName, long processingTimeMillis, @Nullable Throwable failureCause) { super(source, sessionId, userName, processingTimeMillis, failureCause); this.requestUrl = requestUrl; @@ -108,8 +110,8 @@ public class ServletRequestHandledEvent extends RequestHandledEvent { * @param statusCode the HTTP status code of the response */ public ServletRequestHandledEvent(Object source, String requestUrl, - String clientAddress, String method, String servletName, String sessionId, - String userName, long processingTimeMillis, Throwable failureCause, int statusCode) { + String clientAddress, String method, String servletName, @Nullable String sessionId, + @Nullable String userName, long processingTimeMillis, @Nullable Throwable failureCause, int statusCode) { super(source, sessionId, userName, processingTimeMillis, failureCause); this.requestUrl = requestUrl; diff --git a/spring-web/src/main/java/org/springframework/web/context/support/WebApplicationContextUtils.java b/spring-web/src/main/java/org/springframework/web/context/support/WebApplicationContextUtils.java index cd34437310..8531a4bd0d 100644 --- a/spring-web/src/main/java/org/springframework/web/context/support/WebApplicationContextUtils.java +++ b/spring-web/src/main/java/org/springframework/web/context/support/WebApplicationContextUtils.java @@ -21,6 +21,7 @@ import java.util.Collections; import java.util.Enumeration; import java.util.HashMap; import java.util.Map; + import javax.faces.context.ExternalContext; import javax.faces.context.FacesContext; import javax.servlet.ServletConfig; @@ -33,6 +34,7 @@ import org.springframework.beans.factory.ObjectFactory; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.core.env.MutablePropertySources; import org.springframework.core.env.PropertySource.StubPropertySource; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.web.context.ConfigurableWebApplicationContext; @@ -94,6 +96,7 @@ public abstract class WebApplicationContextUtils { * @return the root WebApplicationContext for this web app, or {@code null} if none * @see org.springframework.web.context.WebApplicationContext#ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE */ + @Nullable public static WebApplicationContext getWebApplicationContext(ServletContext sc) { return getWebApplicationContext(sc, WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE); } @@ -104,6 +107,7 @@ public abstract class WebApplicationContextUtils { * @param attrName the name of the ServletContext attribute to look for * @return the desired WebApplicationContext for this web app, or {@code null} if none */ + @Nullable public static WebApplicationContext getWebApplicationContext(ServletContext sc, String attrName) { Assert.notNull(sc, "ServletContext must not be null"); Object attr = sc.getAttribute(attrName); @@ -140,6 +144,7 @@ public abstract class WebApplicationContextUtils { * @see #getWebApplicationContext(ServletContext) * @see ServletContext#getAttributeNames() */ + @Nullable public static WebApplicationContext findWebApplicationContext(ServletContext sc) { WebApplicationContext wac = getWebApplicationContext(sc); if (wac == null) { @@ -285,7 +290,7 @@ public abstract class WebApplicationContextUtils { * @see org.springframework.core.env.ConfigurableEnvironment#getPropertySources() */ public static void initServletPropertySources( - MutablePropertySources propertySources, ServletContext servletContext, ServletConfig servletConfig) { + MutablePropertySources propertySources, @Nullable ServletContext servletContext, @Nullable ServletConfig servletConfig) { Assert.notNull(propertySources, "'propertySources' must not be null"); if (servletContext != null && propertySources.contains(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME) && diff --git a/spring-web/src/main/java/org/springframework/web/context/support/WebApplicationObjectSupport.java b/spring-web/src/main/java/org/springframework/web/context/support/WebApplicationObjectSupport.java index 209a87ddf0..c9efc3e5ed 100644 --- a/spring-web/src/main/java/org/springframework/web/context/support/WebApplicationObjectSupport.java +++ b/spring-web/src/main/java/org/springframework/web/context/support/WebApplicationObjectSupport.java @@ -21,6 +21,7 @@ import javax.servlet.ServletContext; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ApplicationObjectSupport; +import org.springframework.lang.Nullable; import org.springframework.web.context.ServletContextAware; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.util.WebUtils; @@ -103,6 +104,7 @@ public abstract class WebApplicationObjectSupport extends ApplicationObjectSuppo * @throws IllegalStateException if not running in a WebApplicationContext * @see #getApplicationContext() */ + @Nullable protected final WebApplicationContext getWebApplicationContext() throws IllegalStateException { ApplicationContext ctx = getApplicationContext(); if (ctx instanceof WebApplicationContext) { @@ -121,6 +123,7 @@ public abstract class WebApplicationObjectSupport extends ApplicationObjectSuppo * Return the current ServletContext. * @throws IllegalStateException if not running within a ServletContext */ + @Nullable protected final ServletContext getServletContext() throws IllegalStateException { if (this.servletContext != null) { return this.servletContext; diff --git a/spring-web/src/main/java/org/springframework/web/context/support/package-info.java b/spring-web/src/main/java/org/springframework/web/context/support/package-info.java index 6185f654c1..7090f65429 100644 --- a/spring-web/src/main/java/org/springframework/web/context/support/package-info.java +++ b/spring-web/src/main/java/org/springframework/web/context/support/package-info.java @@ -2,4 +2,7 @@ * Classes supporting the {@code org.springframework.web.context} package, * such as WebApplicationContext implementations and various utility classes. */ +@NonNullApi package org.springframework.web.context.support; + +import org.springframework.lang.NonNullApi; diff --git a/spring-web/src/main/java/org/springframework/web/cors/CorsConfiguration.java b/spring-web/src/main/java/org/springframework/web/cors/CorsConfiguration.java index 1a7a368da9..27a281e033 100644 --- a/spring-web/src/main/java/org/springframework/web/cors/CorsConfiguration.java +++ b/spring-web/src/main/java/org/springframework/web/cors/CorsConfiguration.java @@ -24,6 +24,7 @@ import java.util.List; import java.util.Set; import org.springframework.http.HttpMethod; +import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; @@ -116,6 +117,7 @@ public class CorsConfiguration { * @see #addAllowedOrigin(String) * @see #setAllowedOrigins(List) */ + @Nullable public List getAllowedOrigins() { return this.allowedOrigins; } @@ -161,6 +163,7 @@ public class CorsConfiguration { * @see #addAllowedMethod(String) * @see #setAllowedMethods(List) */ + @Nullable public List getAllowedMethods() { return this.allowedMethods; } @@ -212,6 +215,7 @@ public class CorsConfiguration { * @see #addAllowedHeader(String) * @see #setAllowedHeaders(List) */ + @Nullable public List getAllowedHeaders() { return this.allowedHeaders; } @@ -246,6 +250,7 @@ public class CorsConfiguration { * @see #addExposedHeader(String) * @see #setExposedHeaders(List) */ + @Nullable public List getExposedHeaders() { return this.exposedHeaders; } @@ -276,6 +281,7 @@ public class CorsConfiguration { * Return the configured {@code allowCredentials} flag, or {@code null} if none. * @see #setAllowCredentials(Boolean) */ + @Nullable public Boolean getAllowCredentials() { return this.allowCredentials; } @@ -293,6 +299,7 @@ public class CorsConfiguration { * Return the configured {@code maxAge} value, or {@code null} if none. * @see #setMaxAge(Long) */ + @Nullable public Long getMaxAge() { return this.maxAge; } @@ -343,6 +350,7 @@ public class CorsConfiguration { * @return the combined {@code CorsConfiguration} or {@code this} * configuration if the supplied configuration is {@code null} */ + @Nullable public CorsConfiguration combine(CorsConfiguration other) { if (other == null) { return this; @@ -381,6 +389,7 @@ public class CorsConfiguration { * @return the origin to use for the response, or {@code null} which * means the request origin is not allowed */ + @Nullable public String checkOrigin(String requestOrigin) { if (!StringUtils.hasText(requestOrigin)) { return null; @@ -414,6 +423,7 @@ public class CorsConfiguration { * @return the list of HTTP methods to list in the response of a pre-flight * request, or {@code null} if the supplied {@code requestMethod} is not allowed */ + @Nullable public List checkHttpMethod(HttpMethod requestMethod) { if (requestMethod == null) { return null; @@ -432,6 +442,7 @@ public class CorsConfiguration { * @return the list of allowed headers to list in the response of a pre-flight * request, or {@code null} if none of the supplied request headers is allowed */ + @Nullable public List checkHeaders(List requestHeaders) { if (requestHeaders == null) { return null; diff --git a/spring-web/src/main/java/org/springframework/web/cors/CorsConfigurationSource.java b/spring-web/src/main/java/org/springframework/web/cors/CorsConfigurationSource.java index 48166caa19..fae4b31863 100644 --- a/spring-web/src/main/java/org/springframework/web/cors/CorsConfigurationSource.java +++ b/spring-web/src/main/java/org/springframework/web/cors/CorsConfigurationSource.java @@ -18,6 +18,8 @@ package org.springframework.web.cors; import javax.servlet.http.HttpServletRequest; +import org.springframework.lang.Nullable; + /** * Interface to be implemented by classes (usually HTTP request handlers) that * provides a {@link CorsConfiguration} instance based on the provided request. @@ -31,6 +33,7 @@ public interface CorsConfigurationSource { * Return a {@link CorsConfiguration} based on the incoming request. * @return the associated {@link CorsConfiguration}, or {@code null} if none */ + @Nullable CorsConfiguration getCorsConfiguration(HttpServletRequest request); } diff --git a/spring-web/src/main/java/org/springframework/web/cors/CorsProcessor.java b/spring-web/src/main/java/org/springframework/web/cors/CorsProcessor.java index 2794cb4c4d..302e6657ef 100644 --- a/spring-web/src/main/java/org/springframework/web/cors/CorsProcessor.java +++ b/spring-web/src/main/java/org/springframework/web/cors/CorsProcessor.java @@ -17,9 +17,12 @@ package org.springframework.web.cors; import java.io.IOException; + import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.springframework.lang.Nullable; + /** * A strategy that takes a request and a {@link CorsConfiguration} and updates * the response. @@ -44,7 +47,7 @@ public interface CorsProcessor { * @param response the current response * @return {@code false} if the request is rejected, {@code true} otherwise */ - boolean processRequest(CorsConfiguration configuration, HttpServletRequest request, + boolean processRequest(@Nullable CorsConfiguration configuration, HttpServletRequest request, HttpServletResponse response) throws IOException; } diff --git a/spring-web/src/main/java/org/springframework/web/cors/package-info.java b/spring-web/src/main/java/org/springframework/web/cors/package-info.java index 8331aec38e..0fb2394c1d 100644 --- a/spring-web/src/main/java/org/springframework/web/cors/package-info.java +++ b/spring-web/src/main/java/org/springframework/web/cors/package-info.java @@ -2,4 +2,7 @@ * Support for CORS (Cross-Origin Resource Sharing), * based on a common {@code CorsProcessor} strategy. */ +@NonNullApi package org.springframework.web.cors; + +import org.springframework.lang.NonNullApi; diff --git a/spring-web/src/main/java/org/springframework/web/cors/reactive/CorsConfigurationSource.java b/spring-web/src/main/java/org/springframework/web/cors/reactive/CorsConfigurationSource.java index c0fc6e8f92..9ff7a23bbd 100644 --- a/spring-web/src/main/java/org/springframework/web/cors/reactive/CorsConfigurationSource.java +++ b/spring-web/src/main/java/org/springframework/web/cors/reactive/CorsConfigurationSource.java @@ -16,6 +16,7 @@ package org.springframework.web.cors.reactive; +import org.springframework.lang.Nullable; import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.server.ServerWebExchange; @@ -32,6 +33,7 @@ public interface CorsConfigurationSource { * Return a {@link CorsConfiguration} based on the incoming request. * @return the associated {@link CorsConfiguration}, or {@code null} if none */ + @Nullable CorsConfiguration getCorsConfiguration(ServerWebExchange exchange); } diff --git a/spring-web/src/main/java/org/springframework/web/cors/reactive/CorsProcessor.java b/spring-web/src/main/java/org/springframework/web/cors/reactive/CorsProcessor.java index b516b77893..91c845970f 100644 --- a/spring-web/src/main/java/org/springframework/web/cors/reactive/CorsProcessor.java +++ b/spring-web/src/main/java/org/springframework/web/cors/reactive/CorsProcessor.java @@ -18,6 +18,7 @@ package org.springframework.web.cors.reactive; import reactor.core.publisher.Mono; +import org.springframework.lang.Nullable; import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.server.ServerWebExchange; @@ -43,6 +44,6 @@ public interface CorsProcessor { * @param exchange the current HTTP request / response * @return a {@link Mono} emitting {@code false} if the request is rejected, {@code true} otherwise */ - boolean processRequest(CorsConfiguration configuration, ServerWebExchange exchange); + boolean processRequest(@Nullable CorsConfiguration configuration, ServerWebExchange exchange); } diff --git a/spring-web/src/main/java/org/springframework/web/cors/reactive/UrlBasedCorsConfigurationSource.java b/spring-web/src/main/java/org/springframework/web/cors/reactive/UrlBasedCorsConfigurationSource.java index 9fb2c74d54..f1eaa47e25 100644 --- a/spring-web/src/main/java/org/springframework/web/cors/reactive/UrlBasedCorsConfigurationSource.java +++ b/spring-web/src/main/java/org/springframework/web/cors/reactive/UrlBasedCorsConfigurationSource.java @@ -100,7 +100,6 @@ public class UrlBasedCorsConfigurationSource implements CorsConfigurationSource this.corsConfigurations.put(path, config); } - @Override public CorsConfiguration getCorsConfiguration(ServerWebExchange exchange) { String lookupPath = this.pathHelper.getLookupPathForRequest(exchange); diff --git a/spring-web/src/main/java/org/springframework/web/cors/reactive/package-info.java b/spring-web/src/main/java/org/springframework/web/cors/reactive/package-info.java new file mode 100644 index 0000000000..4f9bbeacf2 --- /dev/null +++ b/spring-web/src/main/java/org/springframework/web/cors/reactive/package-info.java @@ -0,0 +1,8 @@ +/** + * Reactive support for CORS (Cross-Origin Resource Sharing), + * based on a common {@code CorsProcessor} strategy. + */ +@NonNullApi +package org.springframework.web.cors.reactive; + +import org.springframework.lang.NonNullApi; diff --git a/spring-web/src/main/java/org/springframework/web/filter/DelegatingFilterProxy.java b/spring-web/src/main/java/org/springframework/web/filter/DelegatingFilterProxy.java index ba5bb5813b..6a665855a0 100644 --- a/spring-web/src/main/java/org/springframework/web/filter/DelegatingFilterProxy.java +++ b/spring-web/src/main/java/org/springframework/web/filter/DelegatingFilterProxy.java @@ -17,6 +17,7 @@ package org.springframework.web.filter; import java.io.IOException; + import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.ServletException; @@ -24,6 +25,7 @@ import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.support.WebApplicationContextUtils; @@ -156,7 +158,7 @@ public class DelegatingFilterProxy extends GenericFilterBean { * @see #findWebApplicationContext() * @see #setEnvironment(org.springframework.core.env.Environment) */ - public DelegatingFilterProxy(String targetBeanName, WebApplicationContext wac) { + public DelegatingFilterProxy(String targetBeanName, @Nullable WebApplicationContext wac) { Assert.hasText(targetBeanName, "target Filter bean name must not be null or empty"); this.setTargetBeanName(targetBeanName); this.webApplicationContext = wac; @@ -287,6 +289,7 @@ public class DelegatingFilterProxy extends GenericFilterBean { * @see WebApplicationContextUtils#getWebApplicationContext(javax.servlet.ServletContext) * @see WebApplicationContext#ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE */ + @Nullable protected WebApplicationContext findWebApplicationContext() { if (this.webApplicationContext != null) { // The user has injected a context at construction time -> use it... diff --git a/spring-web/src/main/java/org/springframework/web/filter/GenericFilterBean.java b/spring-web/src/main/java/org/springframework/web/filter/GenericFilterBean.java index e79408ae57..5a0b54cc8c 100644 --- a/spring-web/src/main/java/org/springframework/web/filter/GenericFilterBean.java +++ b/spring-web/src/main/java/org/springframework/web/filter/GenericFilterBean.java @@ -19,6 +19,7 @@ package org.springframework.web.filter; import java.util.Enumeration; import java.util.HashSet; import java.util.Set; + import javax.servlet.Filter; import javax.servlet.FilterConfig; import javax.servlet.ServletContext; @@ -42,6 +43,7 @@ import org.springframework.core.env.EnvironmentCapable; import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceEditor; import org.springframework.core.io.ResourceLoader; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; @@ -274,6 +276,7 @@ public abstract class GenericFilterBean implements Filter, BeanNameAware, Enviro * @return the FilterConfig instance, or {@code null} if none available * @see javax.servlet.GenericServlet#getServletConfig() */ + @Nullable public final FilterConfig getFilterConfig() { return this.filterConfig; } @@ -289,6 +292,7 @@ public abstract class GenericFilterBean implements Filter, BeanNameAware, Enviro * @see javax.servlet.FilterConfig#getFilterName() * @see #setBeanName */ + @Nullable protected final String getFilterName() { return (this.filterConfig != null ? this.filterConfig.getFilterName() : this.beanName); } @@ -304,6 +308,7 @@ public abstract class GenericFilterBean implements Filter, BeanNameAware, Enviro * @see javax.servlet.FilterConfig#getServletContext() * @see #setServletContext */ + @Nullable protected final ServletContext getServletContext() { return (this.filterConfig != null ? this.filterConfig.getServletContext() : this.servletContext); } diff --git a/spring-web/src/main/java/org/springframework/web/filter/package-info.java b/spring-web/src/main/java/org/springframework/web/filter/package-info.java index 1cfca2cc1e..e48b8b4445 100644 --- a/spring-web/src/main/java/org/springframework/web/filter/package-info.java +++ b/spring-web/src/main/java/org/springframework/web/filter/package-info.java @@ -1,4 +1,7 @@ /** * Provides generic filter base classes allowing for bean-style configuration. */ +@NonNullApi package org.springframework.web.filter; + +import org.springframework.lang.NonNullApi; diff --git a/spring-web/src/main/java/org/springframework/web/filter/reactive/package-info.java b/spring-web/src/main/java/org/springframework/web/filter/reactive/package-info.java index 07a3b12da7..5dfc7049b6 100644 --- a/spring-web/src/main/java/org/springframework/web/filter/reactive/package-info.java +++ b/spring-web/src/main/java/org/springframework/web/filter/reactive/package-info.java @@ -2,4 +2,7 @@ * {@link org.springframework.web.server.WebFilter} implementations for use in * reactive web applications. */ +@NonNullApi package org.springframework.web.filter.reactive; + +import org.springframework.lang.NonNullApi; diff --git a/spring-web/src/main/java/org/springframework/web/jsf/DecoratingNavigationHandler.java b/spring-web/src/main/java/org/springframework/web/jsf/DecoratingNavigationHandler.java index 3726b0962e..e420cdd172 100644 --- a/spring-web/src/main/java/org/springframework/web/jsf/DecoratingNavigationHandler.java +++ b/spring-web/src/main/java/org/springframework/web/jsf/DecoratingNavigationHandler.java @@ -19,6 +19,8 @@ package org.springframework.web.jsf; import javax.faces.application.NavigationHandler; import javax.faces.context.FacesContext; +import org.springframework.lang.Nullable; + /** * Base class for JSF NavigationHandler implementations that want * to be capable of decorating an original NavigationHandler. @@ -58,6 +60,7 @@ public abstract class DecoratingNavigationHandler extends NavigationHandler { * Return the fixed original NavigationHandler decorated by this handler, if any * (that is, if passed in through the constructor). */ + @Nullable public final NavigationHandler getDecoratedNavigationHandler() { return this.decoratedNavigationHandler; } @@ -95,7 +98,7 @@ public abstract class DecoratingNavigationHandler extends NavigationHandler { * @see #callNextHandlerInChain */ public abstract void handleNavigation( - FacesContext facesContext, String fromAction, String outcome, NavigationHandler originalNavigationHandler); + FacesContext facesContext, @Nullable String fromAction, @Nullable String outcome, @Nullable NavigationHandler originalNavigationHandler); /** @@ -127,7 +130,7 @@ public abstract class DecoratingNavigationHandler extends NavigationHandler { * or {@code null} if none */ protected final void callNextHandlerInChain( - FacesContext facesContext, String fromAction, String outcome, NavigationHandler originalNavigationHandler) { + FacesContext facesContext, @Nullable String fromAction, @Nullable String outcome, @Nullable NavigationHandler originalNavigationHandler) { NavigationHandler decoratedNavigationHandler = getDecoratedNavigationHandler(); diff --git a/spring-web/src/main/java/org/springframework/web/jsf/FacesContextUtils.java b/spring-web/src/main/java/org/springframework/web/jsf/FacesContextUtils.java index cbf07194df..e7deb525ca 100644 --- a/spring-web/src/main/java/org/springframework/web/jsf/FacesContextUtils.java +++ b/spring-web/src/main/java/org/springframework/web/jsf/FacesContextUtils.java @@ -19,6 +19,7 @@ package org.springframework.web.jsf; import javax.faces.context.ExternalContext; import javax.faces.context.FacesContext; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.util.WebUtils; @@ -46,6 +47,7 @@ public abstract class FacesContextUtils { * @return the root WebApplicationContext for this web app, or {@code null} if none * @see org.springframework.web.context.WebApplicationContext#ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE */ + @Nullable public static WebApplicationContext getWebApplicationContext(FacesContext fc) { Assert.notNull(fc, "FacesContext must not be null"); Object attr = fc.getExternalContext().getApplicationMap().get( @@ -103,6 +105,7 @@ public abstract class FacesContextUtils { * @see org.springframework.web.util.WebUtils#SESSION_MUTEX_ATTRIBUTE * @see org.springframework.web.util.HttpSessionMutexListener */ + @Nullable public static Object getSessionMutex(FacesContext fc) { Assert.notNull(fc, "FacesContext must not be null"); ExternalContext ec = fc.getExternalContext(); diff --git a/spring-web/src/main/java/org/springframework/web/jsf/el/WebApplicationContextFacesELResolver.java b/spring-web/src/main/java/org/springframework/web/jsf/el/WebApplicationContextFacesELResolver.java index faab2f4216..b653b25b86 100644 --- a/spring-web/src/main/java/org/springframework/web/jsf/el/WebApplicationContextFacesELResolver.java +++ b/spring-web/src/main/java/org/springframework/web/jsf/el/WebApplicationContextFacesELResolver.java @@ -18,6 +18,7 @@ package org.springframework.web.jsf.el; import java.beans.FeatureDescriptor; import java.util.Iterator; + import javax.el.ELContext; import javax.el.ELException; import javax.el.ELResolver; @@ -27,6 +28,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.BeansException; +import org.springframework.lang.Nullable; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.jsf.FacesContextUtils; @@ -66,6 +68,7 @@ public class WebApplicationContextFacesELResolver extends ELResolver { @Override + @Nullable public Object getValue(ELContext elContext, Object base, Object property) throws ELException { if (base != null) { if (base instanceof WebApplicationContext) { @@ -103,6 +106,7 @@ public class WebApplicationContextFacesELResolver extends ELResolver { } @Override + @Nullable public Class getType(ELContext elContext, Object base, Object property) throws ELException { if (base != null) { if (base instanceof WebApplicationContext) { @@ -153,6 +157,7 @@ public class WebApplicationContextFacesELResolver extends ELResolver { } @Override + @Nullable public Iterator getFeatureDescriptors(ELContext elContext, Object base) { return null; } @@ -171,6 +176,7 @@ public class WebApplicationContextFacesELResolver extends ELResolver { * @return the Spring web application context * @see org.springframework.web.jsf.FacesContextUtils#getWebApplicationContext */ + @Nullable protected WebApplicationContext getWebApplicationContext(ELContext elContext) { FacesContext facesContext = FacesContext.getCurrentInstance(); return FacesContextUtils.getRequiredWebApplicationContext(facesContext); diff --git a/spring-web/src/main/java/org/springframework/web/jsf/el/package-info.java b/spring-web/src/main/java/org/springframework/web/jsf/el/package-info.java index 955b183993..82afe98ca2 100644 --- a/spring-web/src/main/java/org/springframework/web/jsf/el/package-info.java +++ b/spring-web/src/main/java/org/springframework/web/jsf/el/package-info.java @@ -2,4 +2,7 @@ * ELResolvers for integrating a JSF web layer with a Spring service layer * which is hosted in a Spring root WebApplicationContext. */ +@NonNullApi package org.springframework.web.jsf.el; + +import org.springframework.lang.NonNullApi; diff --git a/spring-web/src/main/java/org/springframework/web/jsf/package-info.java b/spring-web/src/main/java/org/springframework/web/jsf/package-info.java index 6ed9b5f212..5063eaef05 100644 --- a/spring-web/src/main/java/org/springframework/web/jsf/package-info.java +++ b/spring-web/src/main/java/org/springframework/web/jsf/package-info.java @@ -5,4 +5,7 @@ *

    Supports easy access to beans in the Spring root WebApplicationContext * from JSF EL expressions, for example in property values of JSF-managed beans. */ +@NonNullApi package org.springframework.web.jsf; + +import org.springframework.lang.NonNullApi; diff --git a/spring-web/src/main/java/org/springframework/web/method/HandlerMethod.java b/spring-web/src/main/java/org/springframework/web/method/HandlerMethod.java index d1541b5d8f..3297408cff 100644 --- a/spring-web/src/main/java/org/springframework/web/method/HandlerMethod.java +++ b/spring-web/src/main/java/org/springframework/web/method/HandlerMethod.java @@ -29,6 +29,7 @@ import org.springframework.core.MethodParameter; import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.core.annotation.SynthesizingMethodParameter; import org.springframework.http.HttpStatus; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.web.bind.annotation.ResponseStatus; @@ -223,6 +224,7 @@ public class HandlerMethod { * @since 4.3.8 * @see ResponseStatus#code() */ + @Nullable protected HttpStatus getResponseStatus() { return this.responseStatus; } @@ -232,6 +234,7 @@ public class HandlerMethod { * @since 4.3.8 * @see ResponseStatus#reason() */ + @Nullable protected String getResponseStatusReason() { return this.responseStatusReason; } @@ -266,6 +269,7 @@ public class HandlerMethod { * @return the annotation, or {@code null} if none found * @see AnnotatedElementUtils#findMergedAnnotation */ + @Nullable public A getMethodAnnotation(Class annotationType) { return AnnotatedElementUtils.findMergedAnnotation(this.method, annotationType); } diff --git a/spring-web/src/main/java/org/springframework/web/method/annotation/AbstractCookieValueMethodArgumentResolver.java b/spring-web/src/main/java/org/springframework/web/method/annotation/AbstractCookieValueMethodArgumentResolver.java index 9d9383679d..b5949a7224 100644 --- a/spring-web/src/main/java/org/springframework/web/method/annotation/AbstractCookieValueMethodArgumentResolver.java +++ b/spring-web/src/main/java/org/springframework/web/method/annotation/AbstractCookieValueMethodArgumentResolver.java @@ -18,6 +18,7 @@ package org.springframework.web.method.annotation; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.core.MethodParameter; +import org.springframework.lang.Nullable; import org.springframework.web.bind.ServletRequestBindingException; import org.springframework.web.bind.WebDataBinder; import org.springframework.web.bind.annotation.CookieValue; @@ -44,7 +45,7 @@ public abstract class AbstractCookieValueMethodArgumentResolver extends Abstract * placeholder and #{...} SpEL expressions in default values; * or {@code null} if default values are not expected to contain expressions */ - public AbstractCookieValueMethodArgumentResolver(ConfigurableBeanFactory beanFactory) { + public AbstractCookieValueMethodArgumentResolver(@Nullable ConfigurableBeanFactory beanFactory) { super(beanFactory); } diff --git a/spring-web/src/main/java/org/springframework/web/method/annotation/AbstractNamedValueMethodArgumentResolver.java b/spring-web/src/main/java/org/springframework/web/method/annotation/AbstractNamedValueMethodArgumentResolver.java index ba6b3c1703..363e9b2fd3 100644 --- a/spring-web/src/main/java/org/springframework/web/method/annotation/AbstractNamedValueMethodArgumentResolver.java +++ b/spring-web/src/main/java/org/springframework/web/method/annotation/AbstractNamedValueMethodArgumentResolver.java @@ -18,6 +18,7 @@ package org.springframework.web.method.annotation; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; + import javax.servlet.ServletException; import org.springframework.beans.ConversionNotSupportedException; @@ -26,6 +27,7 @@ import org.springframework.beans.factory.config.BeanExpressionContext; import org.springframework.beans.factory.config.BeanExpressionResolver; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.core.MethodParameter; +import org.springframework.lang.Nullable; import org.springframework.web.bind.ServletRequestBindingException; import org.springframework.web.bind.WebDataBinder; import org.springframework.web.bind.annotation.ValueConstants; @@ -79,7 +81,7 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements Handle * and #{...} SpEL expressions in default values, or {@code null} if default * values are not expected to contain expressions */ - public AbstractNamedValueMethodArgumentResolver(ConfigurableBeanFactory beanFactory) { + public AbstractNamedValueMethodArgumentResolver(@Nullable ConfigurableBeanFactory beanFactory) { this.configurableBeanFactory = beanFactory; this.expressionContext = (beanFactory != null ? new BeanExpressionContext(beanFactory, new RequestScope()) : null); @@ -197,6 +199,7 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements Handle * @return the resolved argument (may be {@code null}) * @throws Exception in case of errors */ + @Nullable protected abstract Object resolveName(String name, MethodParameter parameter, NativeWebRequest request) throws Exception; @@ -228,7 +231,7 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements Handle /** * A {@code null} results in a {@code false} value for {@code boolean}s or an exception for other primitives. */ - private Object handleNullValue(String name, Object value, Class paramType) { + private Object handleNullValue(String name, @Nullable Object value, Class paramType) { if (value == null) { if (Boolean.TYPE.equals(paramType)) { return Boolean.FALSE; @@ -251,7 +254,7 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements Handle * @param webRequest the current request */ protected void handleResolvedValue(Object arg, String name, MethodParameter parameter, - ModelAndViewContainer mavContainer, NativeWebRequest webRequest) { + @Nullable ModelAndViewContainer mavContainer, NativeWebRequest webRequest) { } diff --git a/spring-web/src/main/java/org/springframework/web/method/annotation/AbstractWebArgumentResolverAdapter.java b/spring-web/src/main/java/org/springframework/web/method/annotation/AbstractWebArgumentResolverAdapter.java index 78a3b50806..566642cde8 100644 --- a/spring-web/src/main/java/org/springframework/web/method/annotation/AbstractWebArgumentResolverAdapter.java +++ b/spring-web/src/main/java/org/springframework/web/method/annotation/AbstractWebArgumentResolverAdapter.java @@ -20,6 +20,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.core.MethodParameter; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.web.bind.support.WebArgumentResolver; @@ -109,6 +110,7 @@ public abstract class AbstractWebArgumentResolverAdapter implements HandlerMetho /** * Required for access to NativeWebRequest in {@link #supportsParameter}. */ + @Nullable protected abstract NativeWebRequest getWebRequest(); } diff --git a/spring-web/src/main/java/org/springframework/web/method/annotation/ExceptionHandlerMethodResolver.java b/spring-web/src/main/java/org/springframework/web/method/annotation/ExceptionHandlerMethodResolver.java index eac5de7090..c9116e179c 100644 --- a/spring-web/src/main/java/org/springframework/web/method/annotation/ExceptionHandlerMethodResolver.java +++ b/spring-web/src/main/java/org/springframework/web/method/annotation/ExceptionHandlerMethodResolver.java @@ -27,6 +27,7 @@ import java.util.concurrent.ConcurrentHashMap; import org.springframework.core.ExceptionDepthComparator; import org.springframework.core.MethodIntrospector; import org.springframework.core.annotation.AnnotationUtils; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.ReflectionUtils.MethodFilter; @@ -124,6 +125,7 @@ public class ExceptionHandlerMethodResolver { * @param exception the exception * @return a Method to handle the exception, or {@code null} if none found */ + @Nullable public Method resolveMethod(Exception exception) { return resolveMethodByThrowable(exception); } @@ -135,6 +137,7 @@ public class ExceptionHandlerMethodResolver { * @return a Method to handle the exception, or {@code null} if none found * @since 5.0 */ + @Nullable public Method resolveMethodByThrowable(Throwable exception) { Method method = resolveMethodByExceptionType(exception.getClass()); if (method == null) { @@ -152,6 +155,7 @@ public class ExceptionHandlerMethodResolver { * @param exceptionType the exception type * @return a Method to handle the exception, or {@code null} if none found */ + @Nullable public Method resolveMethodByExceptionType(Class exceptionType) { Method method = this.exceptionLookupCache.get(exceptionType); if (method == null) { @@ -164,6 +168,7 @@ public class ExceptionHandlerMethodResolver { /** * Return the {@link Method} mapped to the given exception type, or {@code null} if none. */ + @Nullable private Method getMappedMethod(Class exceptionType) { List> matches = new ArrayList<>(); for (Class mappedException : this.mappedMethods.keySet()) { diff --git a/spring-web/src/main/java/org/springframework/web/method/annotation/ExpressionValueMethodArgumentResolver.java b/spring-web/src/main/java/org/springframework/web/method/annotation/ExpressionValueMethodArgumentResolver.java index 73393f720a..cc0e0248b0 100644 --- a/spring-web/src/main/java/org/springframework/web/method/annotation/ExpressionValueMethodArgumentResolver.java +++ b/spring-web/src/main/java/org/springframework/web/method/annotation/ExpressionValueMethodArgumentResolver.java @@ -21,6 +21,7 @@ import javax.servlet.ServletException; import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.core.MethodParameter; +import org.springframework.lang.Nullable; import org.springframework.web.bind.WebDataBinder; import org.springframework.web.context.request.NativeWebRequest; @@ -44,7 +45,7 @@ public class ExpressionValueMethodArgumentResolver extends AbstractNamedValueMet * placeholder and #{...} SpEL expressions in default values; * or {@code null} if default values are not expected to contain expressions */ - public ExpressionValueMethodArgumentResolver(ConfigurableBeanFactory beanFactory) { + public ExpressionValueMethodArgumentResolver(@Nullable ConfigurableBeanFactory beanFactory) { super(beanFactory); } diff --git a/spring-web/src/main/java/org/springframework/web/method/annotation/InitBinderDataBinderFactory.java b/spring-web/src/main/java/org/springframework/web/method/annotation/InitBinderDataBinderFactory.java index 6223005d1b..b014759766 100644 --- a/spring-web/src/main/java/org/springframework/web/method/annotation/InitBinderDataBinderFactory.java +++ b/spring-web/src/main/java/org/springframework/web/method/annotation/InitBinderDataBinderFactory.java @@ -21,6 +21,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.List; +import org.springframework.lang.Nullable; import org.springframework.web.bind.WebDataBinder; import org.springframework.web.bind.annotation.InitBinder; import org.springframework.web.bind.support.DefaultDataBinderFactory; @@ -45,7 +46,7 @@ public class InitBinderDataBinderFactory extends DefaultDataBinderFactory { * @param binderMethods {@code @InitBinder} methods, or {@code null} * @param initializer for global data binder intialization */ - public InitBinderDataBinderFactory(List binderMethods, + public InitBinderDataBinderFactory(@Nullable List binderMethods, WebBindingInitializer initializer) { super(initializer); diff --git a/spring-web/src/main/java/org/springframework/web/method/annotation/RequestHeaderMethodArgumentResolver.java b/spring-web/src/main/java/org/springframework/web/method/annotation/RequestHeaderMethodArgumentResolver.java index c8575251ce..24d72e25aa 100644 --- a/spring-web/src/main/java/org/springframework/web/method/annotation/RequestHeaderMethodArgumentResolver.java +++ b/spring-web/src/main/java/org/springframework/web/method/annotation/RequestHeaderMethodArgumentResolver.java @@ -20,6 +20,7 @@ import java.util.Map; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.core.MethodParameter; +import org.springframework.lang.Nullable; import org.springframework.web.bind.ServletRequestBindingException; import org.springframework.web.bind.WebDataBinder; import org.springframework.web.bind.annotation.RequestHeader; @@ -48,7 +49,7 @@ public class RequestHeaderMethodArgumentResolver extends AbstractNamedValueMetho * placeholder and #{...} SpEL expressions in default values; * or {@code null} if default values are not expected to have expressions */ - public RequestHeaderMethodArgumentResolver(ConfigurableBeanFactory beanFactory) { + public RequestHeaderMethodArgumentResolver(@Nullable ConfigurableBeanFactory beanFactory) { super(beanFactory); } diff --git a/spring-web/src/main/java/org/springframework/web/method/annotation/RequestParamMethodArgumentResolver.java b/spring-web/src/main/java/org/springframework/web/method/annotation/RequestParamMethodArgumentResolver.java index e7463e05e9..a2c6e41466 100644 --- a/spring-web/src/main/java/org/springframework/web/method/annotation/RequestParamMethodArgumentResolver.java +++ b/spring-web/src/main/java/org/springframework/web/method/annotation/RequestParamMethodArgumentResolver.java @@ -20,6 +20,7 @@ import java.beans.PropertyEditor; import java.util.Collection; import java.util.List; import java.util.Map; + import javax.servlet.http.HttpServletRequest; import javax.servlet.http.Part; @@ -29,6 +30,7 @@ import org.springframework.core.MethodParameter; import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.TypeDescriptor; import org.springframework.core.convert.converter.Converter; +import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; import org.springframework.web.bind.MissingServletRequestParameterException; import org.springframework.web.bind.WebDataBinder; @@ -99,7 +101,7 @@ public class RequestParamMethodArgumentResolver extends AbstractNamedValueMethod * is treated as a request parameter even if it isn't annotated, the * request parameter name is derived from the method parameter name. */ - public RequestParamMethodArgumentResolver(ConfigurableBeanFactory beanFactory, boolean useDefaultResolution) { + public RequestParamMethodArgumentResolver(@Nullable ConfigurableBeanFactory beanFactory, boolean useDefaultResolution) { super(beanFactory); this.useDefaultResolution = useDefaultResolution; } diff --git a/spring-web/src/main/java/org/springframework/web/method/annotation/SessionAttributesHandler.java b/spring-web/src/main/java/org/springframework/web/method/annotation/SessionAttributesHandler.java index d5a5607c9e..51e9ba793c 100644 --- a/spring-web/src/main/java/org/springframework/web/method/annotation/SessionAttributesHandler.java +++ b/spring-web/src/main/java/org/springframework/web/method/annotation/SessionAttributesHandler.java @@ -25,6 +25,7 @@ import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import org.springframework.core.annotation.AnnotatedElementUtils; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.bind.annotation.SessionAttributes; import org.springframework.web.bind.support.SessionAttributeStore; @@ -98,7 +99,7 @@ public class SessionAttributesHandler { * @param attributeName the attribute name to check, never {@code null} * @param attributeType the type for the attribute, possibly {@code null} */ - public boolean isHandlerSessionAttribute(String attributeName, Class attributeType) { + public boolean isHandlerSessionAttribute(String attributeName, @Nullable Class attributeType) { Assert.notNull(attributeName, "Attribute name must not be null"); if (this.attributeNames.contains(attributeName) || this.attributeTypes.contains(attributeType)) { this.knownAttributeNames.add(attributeName); @@ -162,6 +163,7 @@ public class SessionAttributesHandler { * @param attributeName the name of the attribute of interest * @return the attribute value or {@code null} */ + @Nullable Object retrieveAttribute(WebRequest request, String attributeName) { return this.sessionAttributeStore.retrieveAttribute(request, attributeName); } diff --git a/spring-web/src/main/java/org/springframework/web/method/annotation/package-info.java b/spring-web/src/main/java/org/springframework/web/method/annotation/package-info.java index dd12277b7b..46582f2348 100644 --- a/spring-web/src/main/java/org/springframework/web/method/annotation/package-info.java +++ b/spring-web/src/main/java/org/springframework/web/method/annotation/package-info.java @@ -1,4 +1,7 @@ /** * Support classes for annotation-based handler method processing. */ +@NonNullApi package org.springframework.web.method.annotation; + +import org.springframework.lang.NonNullApi; diff --git a/spring-web/src/main/java/org/springframework/web/method/package-info.java b/spring-web/src/main/java/org/springframework/web/method/package-info.java index 5d7b2a78c1..6e13a6e5e6 100644 --- a/spring-web/src/main/java/org/springframework/web/method/package-info.java +++ b/spring-web/src/main/java/org/springframework/web/method/package-info.java @@ -2,4 +2,7 @@ * Common infrastructure for handler method processing, as used by * Spring MVC's {@code org.springframework.web.servlet.mvc.method} package. */ +@NonNullApi package org.springframework.web.method; + +import org.springframework.lang.NonNullApi; diff --git a/spring-web/src/main/java/org/springframework/web/method/support/CompositeUriComponentsContributor.java b/spring-web/src/main/java/org/springframework/web/method/support/CompositeUriComponentsContributor.java index 01f028b0ab..42dfc307e7 100644 --- a/spring-web/src/main/java/org/springframework/web/method/support/CompositeUriComponentsContributor.java +++ b/spring-web/src/main/java/org/springframework/web/method/support/CompositeUriComponentsContributor.java @@ -25,6 +25,7 @@ import java.util.Map; import org.springframework.core.MethodParameter; import org.springframework.core.convert.ConversionService; import org.springframework.format.support.DefaultFormattingConversionService; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.util.UriComponentsBuilder; @@ -84,7 +85,7 @@ public class CompositeUriComponentsContributor implements UriComponentsContribut * @param cs a ConversionService to use when method argument values * need to be formatted as Strings before being added to the URI */ - public CompositeUriComponentsContributor(Collection contributors, ConversionService cs) { + public CompositeUriComponentsContributor(Collection contributors, @Nullable ConversionService cs) { Assert.notNull(contributors, "'uriComponentsContributors' must not be null"); this.contributors.addAll(contributors); this.conversionService = (cs != null ? cs : new DefaultFormattingConversionService()); diff --git a/spring-web/src/main/java/org/springframework/web/method/support/HandlerMethodArgumentResolver.java b/spring-web/src/main/java/org/springframework/web/method/support/HandlerMethodArgumentResolver.java index c5cd168156..3789c08a0f 100644 --- a/spring-web/src/main/java/org/springframework/web/method/support/HandlerMethodArgumentResolver.java +++ b/spring-web/src/main/java/org/springframework/web/method/support/HandlerMethodArgumentResolver.java @@ -17,6 +17,7 @@ package org.springframework.web.method.support; import org.springframework.core.MethodParameter; +import org.springframework.lang.Nullable; import org.springframework.web.bind.WebDataBinder; import org.springframework.web.bind.support.WebDataBinderFactory; import org.springframework.web.context.request.NativeWebRequest; @@ -55,6 +56,7 @@ public interface HandlerMethodArgumentResolver { * @return the resolved argument value, or {@code null} * @throws Exception in case of errors with the preparation of argument values */ + @Nullable Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception; diff --git a/spring-web/src/main/java/org/springframework/web/method/support/HandlerMethodReturnValueHandlerComposite.java b/spring-web/src/main/java/org/springframework/web/method/support/HandlerMethodReturnValueHandlerComposite.java index 7917e28cd7..ba880e32b5 100644 --- a/spring-web/src/main/java/org/springframework/web/method/support/HandlerMethodReturnValueHandlerComposite.java +++ b/spring-web/src/main/java/org/springframework/web/method/support/HandlerMethodReturnValueHandlerComposite.java @@ -24,6 +24,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.core.MethodParameter; +import org.springframework.lang.Nullable; import org.springframework.web.context.request.NativeWebRequest; /** @@ -57,6 +58,7 @@ public class HandlerMethodReturnValueHandlerComposite implements HandlerMethodRe return getReturnValueHandler(returnType) != null; } + @Nullable private HandlerMethodReturnValueHandler getReturnValueHandler(MethodParameter returnType) { for (HandlerMethodReturnValueHandler handler : this.returnValueHandlers) { if (handler.supportsReturnType(returnType)) { @@ -81,6 +83,7 @@ public class HandlerMethodReturnValueHandlerComposite implements HandlerMethodRe handler.handleReturnValue(returnValue, returnType, mavContainer, webRequest); } + @Nullable private HandlerMethodReturnValueHandler selectHandler(Object value, MethodParameter returnType) { boolean isAsyncValue = isAsyncReturnValue(value, returnType); for (HandlerMethodReturnValueHandler handler : this.returnValueHandlers) { diff --git a/spring-web/src/main/java/org/springframework/web/method/support/InvocableHandlerMethod.java b/spring-web/src/main/java/org/springframework/web/method/support/InvocableHandlerMethod.java index 8f6965d7ff..18f2b229e6 100644 --- a/spring-web/src/main/java/org/springframework/web/method/support/InvocableHandlerMethod.java +++ b/spring-web/src/main/java/org/springframework/web/method/support/InvocableHandlerMethod.java @@ -23,6 +23,7 @@ import java.util.Arrays; import org.springframework.core.DefaultParameterNameDiscoverer; import org.springframework.core.MethodParameter; import org.springframework.core.ParameterNameDiscoverer; +import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.util.ReflectionUtils; import org.springframework.web.bind.WebDataBinder; @@ -183,6 +184,7 @@ public class InvocableHandlerMethod extends HandlerMethod { /** * Attempt to resolve a method parameter from the list of provided argument values. */ + @Nullable private Object resolveProvidedArgument(MethodParameter parameter, Object... providedArgs) { if (providedArgs == null) { return null; diff --git a/spring-web/src/main/java/org/springframework/web/method/support/ModelAndViewContainer.java b/spring-web/src/main/java/org/springframework/web/method/support/ModelAndViewContainer.java index 08af03d831..1d67969c90 100644 --- a/spring-web/src/main/java/org/springframework/web/method/support/ModelAndViewContainer.java +++ b/spring-web/src/main/java/org/springframework/web/method/support/ModelAndViewContainer.java @@ -21,6 +21,7 @@ import java.util.Map; import java.util.Set; import org.springframework.http.HttpStatus; +import org.springframework.lang.Nullable; import org.springframework.ui.Model; import org.springframework.ui.ModelMap; import org.springframework.validation.support.BindingAwareModelMap; @@ -95,6 +96,7 @@ public class ModelAndViewContainer { * Return the view name to be resolved by the DispatcherServlet via a * ViewResolver, or {@code null} if a View object is set. */ + @Nullable public String getViewName() { return (this.view instanceof String ? (String) this.view : null); } @@ -111,6 +113,7 @@ public class ModelAndViewContainer { * Return the View object, or {@code null} if we using a view name * to be resolved by the DispatcherServlet via a ViewResolver. */ + @Nullable public Object getView() { return this.view; } @@ -219,6 +222,7 @@ public class ModelAndViewContainer { * Return the configured HTTP status, if any. * @since 4.3 */ + @Nullable public HttpStatus getStatus() { return this.status; } diff --git a/spring-web/src/main/java/org/springframework/web/method/support/package-info.java b/spring-web/src/main/java/org/springframework/web/method/support/package-info.java index 3fe229ede3..379e75e053 100644 --- a/spring-web/src/main/java/org/springframework/web/method/support/package-info.java +++ b/spring-web/src/main/java/org/springframework/web/method/support/package-info.java @@ -1,4 +1,7 @@ /** * Generic support classes for handler method processing. */ +@NonNullApi package org.springframework.web.method.support; + +import org.springframework.lang.NonNullApi; diff --git a/spring-web/src/main/java/org/springframework/web/multipart/MultipartFile.java b/spring-web/src/main/java/org/springframework/web/multipart/MultipartFile.java index 5d27f350f9..7c642d591b 100644 --- a/spring-web/src/main/java/org/springframework/web/multipart/MultipartFile.java +++ b/spring-web/src/main/java/org/springframework/web/multipart/MultipartFile.java @@ -21,6 +21,7 @@ import java.io.IOException; import java.io.InputStream; import org.springframework.core.io.InputStreamSource; +import org.springframework.lang.Nullable; /** * A representation of an uploaded file received in a multipart request. @@ -53,6 +54,7 @@ public interface MultipartFile extends InputStreamSource { * @see org.apache.commons.fileupload.FileItem#getName() * @see org.springframework.web.multipart.commons.CommonsMultipartFile#setPreserveFilename */ + @Nullable String getOriginalFilename(); /** @@ -60,6 +62,7 @@ public interface MultipartFile extends InputStreamSource { * @return the content type, or {@code null} if not defined * (or no file has been chosen in the multipart form) */ + @Nullable String getContentType(); /** diff --git a/spring-web/src/main/java/org/springframework/web/multipart/MultipartHttpServletRequest.java b/spring-web/src/main/java/org/springframework/web/multipart/MultipartHttpServletRequest.java index c5428f08d4..f96305919b 100644 --- a/spring-web/src/main/java/org/springframework/web/multipart/MultipartHttpServletRequest.java +++ b/spring-web/src/main/java/org/springframework/web/multipart/MultipartHttpServletRequest.java @@ -20,6 +20,7 @@ import javax.servlet.http.HttpServletRequest; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; +import org.springframework.lang.Nullable; /** * Provides additional methods for dealing with multipart content within a @@ -62,6 +63,7 @@ public interface MultipartHttpServletRequest extends HttpServletRequest, Multipa *

    If the underlying implementation supports access to headers, then all headers are returned. * Otherwise, the returned headers will include a 'Content-Type' header at the very least. */ + @Nullable HttpHeaders getMultipartHeaders(String paramOrFileName); } diff --git a/spring-web/src/main/java/org/springframework/web/multipart/MultipartRequest.java b/spring-web/src/main/java/org/springframework/web/multipart/MultipartRequest.java index 4dc2cb25d7..ec55d02f4b 100644 --- a/spring-web/src/main/java/org/springframework/web/multipart/MultipartRequest.java +++ b/spring-web/src/main/java/org/springframework/web/multipart/MultipartRequest.java @@ -20,6 +20,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; +import org.springframework.lang.Nullable; import org.springframework.util.MultiValueMap; /** @@ -47,6 +48,7 @@ public interface MultipartRequest { * @param name a String specifying the parameter name of the multipart file * @return the uploaded content in the form of a {@link MultipartFile} object */ + @Nullable MultipartFile getFile(String name); /** @@ -79,6 +81,7 @@ public interface MultipartRequest { * @return the associated content type, or {@code null} if not defined * @since 3.1 */ + @Nullable String getMultipartContentType(String paramOrFileName); } diff --git a/spring-web/src/main/java/org/springframework/web/multipart/commons/package-info.java b/spring-web/src/main/java/org/springframework/web/multipart/commons/package-info.java index 001283a1fe..3021c8c629 100644 --- a/spring-web/src/main/java/org/springframework/web/multipart/commons/package-info.java +++ b/spring-web/src/main/java/org/springframework/web/multipart/commons/package-info.java @@ -2,4 +2,7 @@ * MultipartResolver implementation for * Apache Commons FileUpload. */ +@NonNullApi package org.springframework.web.multipart.commons; + +import org.springframework.lang.NonNullApi; diff --git a/spring-web/src/main/java/org/springframework/web/multipart/package-info.java b/spring-web/src/main/java/org/springframework/web/multipart/package-info.java index 0733fd9436..906d5c8585 100644 --- a/spring-web/src/main/java/org/springframework/web/multipart/package-info.java +++ b/spring-web/src/main/java/org/springframework/web/multipart/package-info.java @@ -4,4 +4,7 @@ * and a generic extension of the HttpServletRequest interface * for accessing multipart files in web application code. */ +@NonNullApi package org.springframework.web.multipart; + +import org.springframework.lang.NonNullApi; diff --git a/spring-web/src/main/java/org/springframework/web/multipart/support/MultipartFilter.java b/spring-web/src/main/java/org/springframework/web/multipart/support/MultipartFilter.java index 577b4e3b85..c6d2ccebb7 100644 --- a/spring-web/src/main/java/org/springframework/web/multipart/support/MultipartFilter.java +++ b/spring-web/src/main/java/org/springframework/web/multipart/support/MultipartFilter.java @@ -17,11 +17,13 @@ package org.springframework.web.multipart.support; import java.io.IOException; + import javax.servlet.FilterChain; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.springframework.lang.Nullable; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.support.WebApplicationContextUtils; import org.springframework.web.filter.OncePerRequestFilter; @@ -148,6 +150,7 @@ public class MultipartFilter extends OncePerRequestFilter { * for example if not using a Spring web application context. * @return the MultipartResolver instance, or {@code null} if none found */ + @Nullable protected MultipartResolver lookupMultipartResolver() { WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(getServletContext()); String beanName = getMultipartResolverBeanName(); diff --git a/spring-web/src/main/java/org/springframework/web/multipart/support/MultipartResolutionDelegate.java b/spring-web/src/main/java/org/springframework/web/multipart/support/MultipartResolutionDelegate.java index d409496bd7..30cdecad09 100644 --- a/spring-web/src/main/java/org/springframework/web/multipart/support/MultipartResolutionDelegate.java +++ b/spring-web/src/main/java/org/springframework/web/multipart/support/MultipartResolutionDelegate.java @@ -24,6 +24,7 @@ import javax.servlet.http.Part; import org.springframework.core.MethodParameter; import org.springframework.core.ResolvableType; +import org.springframework.lang.Nullable; import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartHttpServletRequest; import org.springframework.web.util.WebUtils; @@ -66,6 +67,7 @@ public abstract class MultipartResolutionDelegate { (Part.class == paramType || isPartCollection(parameter) || isPartArray(parameter))); } + @Nullable public static Object resolveMultipartArgument(String name, MethodParameter parameter, HttpServletRequest request) throws Exception { @@ -127,6 +129,7 @@ public abstract class MultipartResolutionDelegate { return (Part.class == methodParam.getNestedParameterType().getComponentType()); } + @Nullable private static Class getCollectionParameterType(MethodParameter methodParam) { Class paramType = methodParam.getNestedParameterType(); if (Collection.class == paramType || List.class.isAssignableFrom(paramType)){ diff --git a/spring-web/src/main/java/org/springframework/web/multipart/support/StandardMultipartHttpServletRequest.java b/spring-web/src/main/java/org/springframework/web/multipart/support/StandardMultipartHttpServletRequest.java index c631932cbc..c84ac00679 100644 --- a/spring-web/src/main/java/org/springframework/web/multipart/support/StandardMultipartHttpServletRequest.java +++ b/spring-web/src/main/java/org/springframework/web/multipart/support/StandardMultipartHttpServletRequest.java @@ -35,6 +35,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.Part; import org.springframework.http.HttpHeaders; +import org.springframework.lang.Nullable; import org.springframework.util.FileCopyUtils; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; @@ -121,6 +122,7 @@ public class StandardMultipartHttpServletRequest extends AbstractMultipartHttpSe throw new MultipartException("Failed to parse multipart servlet request", ex); } + @Nullable private String extractFilename(String contentDisposition, String key) { if (contentDisposition == null) { return null; @@ -149,6 +151,7 @@ public class StandardMultipartHttpServletRequest extends AbstractMultipartHttpSe return extractFilename(contentDisposition, FILENAME_KEY); } + @Nullable private String extractFilenameWithCharset(String contentDisposition) { String filename = extractFilename(contentDisposition, FILENAME_WITH_CHARSET_KEY); if (filename == null) { diff --git a/spring-web/src/main/java/org/springframework/web/multipart/support/package-info.java b/spring-web/src/main/java/org/springframework/web/multipart/support/package-info.java index 351cb24816..234f6b4453 100644 --- a/spring-web/src/main/java/org/springframework/web/multipart/support/package-info.java +++ b/spring-web/src/main/java/org/springframework/web/multipart/support/package-info.java @@ -3,4 +3,7 @@ * Contains property editors for multipart files, and a Servlet filter * for multipart handling without Spring's Web MVC. */ +@NonNullApi package org.springframework.web.multipart.support; + +import org.springframework.lang.NonNullApi; diff --git a/spring-web/src/main/java/org/springframework/web/package-info.java b/spring-web/src/main/java/org/springframework/web/package-info.java index 142f096ec7..4780c3f889 100644 --- a/spring-web/src/main/java/org/springframework/web/package-info.java +++ b/spring-web/src/main/java/org/springframework/web/package-info.java @@ -2,4 +2,7 @@ * Common, generic interfaces that define minimal boundary points * between Spring's web infrastructure and other framework modules. */ +@NonNullApi package org.springframework.web; + +import org.springframework.lang.NonNullApi; diff --git a/spring-web/src/main/java/org/springframework/web/server/ResponseStatusException.java b/spring-web/src/main/java/org/springframework/web/server/ResponseStatusException.java index 198b5a05ff..0bbc5d0e0b 100644 --- a/spring-web/src/main/java/org/springframework/web/server/ResponseStatusException.java +++ b/spring-web/src/main/java/org/springframework/web/server/ResponseStatusException.java @@ -19,6 +19,7 @@ package org.springframework.web.server; import org.springframework.core.NestedExceptionUtils; import org.springframework.core.NestedRuntimeException; import org.springframework.http.HttpStatus; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -50,7 +51,7 @@ public class ResponseStatusException extends NestedRuntimeException { * @param status the HTTP status (required) * @param reason the associated reason (optional) */ - public ResponseStatusException(HttpStatus status, String reason) { + public ResponseStatusException(HttpStatus status, @Nullable String reason) { this(status, reason, null); } @@ -61,7 +62,7 @@ public class ResponseStatusException extends NestedRuntimeException { * @param reason the associated reason (optional) * @param cause a nested exception (optional) */ - public ResponseStatusException(HttpStatus status, String reason, Throwable cause) { + public ResponseStatusException(HttpStatus status, @Nullable String reason, @Nullable Throwable cause) { super(null, cause); Assert.notNull(status, "HttpStatus is required"); this.status = status; @@ -79,6 +80,7 @@ public class ResponseStatusException extends NestedRuntimeException { /** * The reason explaining the exception (potentially {@code null} or empty). */ + @Nullable public String getReason() { return this.reason; } diff --git a/spring-web/src/main/java/org/springframework/web/server/ServerErrorException.java b/spring-web/src/main/java/org/springframework/web/server/ServerErrorException.java index 513a67fbbf..e914ad629b 100644 --- a/spring-web/src/main/java/org/springframework/web/server/ServerErrorException.java +++ b/spring-web/src/main/java/org/springframework/web/server/ServerErrorException.java @@ -18,6 +18,7 @@ package org.springframework.web.server; import org.springframework.core.MethodParameter; import org.springframework.http.HttpStatus; +import org.springframework.lang.Nullable; /** * Exception for errors that fit response status 500 (bad request) for use in @@ -59,6 +60,7 @@ public class ServerErrorException extends ResponseStatusException { /** * Return the {@code MethodParameter} associated with this error, if any. */ + @Nullable public MethodParameter getMethodParameter() { return this.parameter; } diff --git a/spring-web/src/main/java/org/springframework/web/server/ServerWebInputException.java b/spring-web/src/main/java/org/springframework/web/server/ServerWebInputException.java index 91f60f4304..3c94c409f1 100644 --- a/spring-web/src/main/java/org/springframework/web/server/ServerWebInputException.java +++ b/spring-web/src/main/java/org/springframework/web/server/ServerWebInputException.java @@ -18,6 +18,7 @@ package org.springframework.web.server; import org.springframework.core.MethodParameter; import org.springframework.http.HttpStatus; +import org.springframework.lang.Nullable; /** * Exception for errors that fit response status 400 (bad request) for use in @@ -59,6 +60,7 @@ public class ServerWebInputException extends ResponseStatusException { /** * Return the {@code MethodParameter} associated with this error, if any. */ + @Nullable public MethodParameter getMethodParameter() { return this.parameter; } diff --git a/spring-web/src/main/java/org/springframework/web/server/UnsupportedMediaTypeStatusException.java b/spring-web/src/main/java/org/springframework/web/server/UnsupportedMediaTypeStatusException.java index 308951a297..84f354efc2 100644 --- a/spring-web/src/main/java/org/springframework/web/server/UnsupportedMediaTypeStatusException.java +++ b/spring-web/src/main/java/org/springframework/web/server/UnsupportedMediaTypeStatusException.java @@ -21,6 +21,7 @@ import java.util.List; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; +import org.springframework.lang.Nullable; /** * Exception for errors that fit response status 416 (unsupported media type). @@ -59,6 +60,7 @@ public class UnsupportedMediaTypeStatusException extends ResponseStatusException * Return the request Content-Type header if it was parsed successfully, * or {@code null} otherwise. */ + @Nullable public MediaType getContentType() { return this.contentType; } diff --git a/spring-web/src/main/java/org/springframework/web/server/adapter/package-info.java b/spring-web/src/main/java/org/springframework/web/server/adapter/package-info.java index 8f20e00d33..51c295df38 100644 --- a/spring-web/src/main/java/org/springframework/web/server/adapter/package-info.java +++ b/spring-web/src/main/java/org/springframework/web/server/adapter/package-info.java @@ -3,4 +3,7 @@ * {@code org.springframework.http.client.reactive} reactive HTTP adapter * and {@link org.springframework.http.server.reactive.HttpHandler}. */ +@NonNullApi package org.springframework.web.server.adapter; + +import org.springframework.lang.NonNullApi; diff --git a/spring-web/src/main/java/org/springframework/web/server/handler/package-info.java b/spring-web/src/main/java/org/springframework/web/server/handler/package-info.java index 77da5259e8..091e1784db 100644 --- a/spring-web/src/main/java/org/springframework/web/server/handler/package-info.java +++ b/spring-web/src/main/java/org/springframework/web/server/handler/package-info.java @@ -2,4 +2,7 @@ * Provides common WebHandler implementations and a * {@link org.springframework.web.server.handler.WebHandlerDecorator}. */ +@NonNullApi package org.springframework.web.server.handler; + +import org.springframework.lang.NonNullApi; diff --git a/spring-web/src/main/java/org/springframework/web/server/package-info.java b/spring-web/src/main/java/org/springframework/web/server/package-info.java index dda2f5dbef..fbe43f7b52 100644 --- a/spring-web/src/main/java/org/springframework/web/server/package-info.java +++ b/spring-web/src/main/java/org/springframework/web/server/package-info.java @@ -4,4 +4,7 @@ * reactive HTTP adapter layer, providing additional constructs such as * WebHandler, WebFilter, WebSession among others. */ +@NonNullApi package org.springframework.web.server; + +import org.springframework.lang.NonNullApi; diff --git a/spring-web/src/main/java/org/springframework/web/server/session/package-info.java b/spring-web/src/main/java/org/springframework/web/server/session/package-info.java index e0a1afc065..46fdc33681 100644 --- a/spring-web/src/main/java/org/springframework/web/server/session/package-info.java +++ b/spring-web/src/main/java/org/springframework/web/server/session/package-info.java @@ -2,4 +2,7 @@ * Auxiliary interfaces and implementation classes for * {@link org.springframework.web.server.WebSession} support. */ +@NonNullApi package org.springframework.web.server.session; + +import org.springframework.lang.NonNullApi; diff --git a/spring-web/src/main/java/org/springframework/web/server/support/package-info.java b/spring-web/src/main/java/org/springframework/web/server/support/package-info.java index 0220d7faa4..93a8f72871 100644 --- a/spring-web/src/main/java/org/springframework/web/server/support/package-info.java +++ b/spring-web/src/main/java/org/springframework/web/server/support/package-info.java @@ -2,4 +2,7 @@ * Helper classes on top of {@code org.springframework.web.server}, * as a convenience for working with {@code ServerWebExchange}. */ +@NonNullApi package org.springframework.web.server.support; + +import org.springframework.lang.NonNullApi; diff --git a/spring-web/src/main/java/org/springframework/web/util/CookieGenerator.java b/spring-web/src/main/java/org/springframework/web/util/CookieGenerator.java index 59f5b22680..475b84c641 100644 --- a/spring-web/src/main/java/org/springframework/web/util/CookieGenerator.java +++ b/spring-web/src/main/java/org/springframework/web/util/CookieGenerator.java @@ -22,6 +22,7 @@ import javax.servlet.http.HttpServletResponse; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -89,6 +90,7 @@ public class CookieGenerator { /** * Return the domain for cookies created by this generator, if any. */ + @Nullable public String getCookieDomain() { return this.cookieDomain; } diff --git a/spring-web/src/main/java/org/springframework/web/util/HierarchicalUriComponents.java b/spring-web/src/main/java/org/springframework/web/util/HierarchicalUriComponents.java index 86bd732c40..a8c02ba996 100644 --- a/spring-web/src/main/java/org/springframework/web/util/HierarchicalUriComponents.java +++ b/spring-web/src/main/java/org/springframework/web/util/HierarchicalUriComponents.java @@ -28,6 +28,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.util.LinkedMultiValueMap; @@ -78,9 +79,9 @@ final class HierarchicalUriComponents extends UriComponents { * @param encoded whether the components are already encoded * @param verify whether the components need to be checked for illegal characters */ - HierarchicalUriComponents(String scheme, String userInfo, String host, String port, - PathComponent path, MultiValueMap queryParams, - String fragment, boolean encoded, boolean verify) { + HierarchicalUriComponents(@Nullable String scheme, @Nullable String userInfo, @Nullable String host, @Nullable String port, + @Nullable PathComponent path, @Nullable MultiValueMap queryParams, + @Nullable String fragment, @Nullable boolean encoded, @Nullable boolean verify) { super(scheme, fragment); this.userInfo = userInfo; diff --git a/spring-web/src/main/java/org/springframework/web/util/HtmlCharacterEntityReferences.java b/spring-web/src/main/java/org/springframework/web/util/HtmlCharacterEntityReferences.java index 2757be9172..1e00db13f5 100644 --- a/spring-web/src/main/java/org/springframework/web/util/HtmlCharacterEntityReferences.java +++ b/spring-web/src/main/java/org/springframework/web/util/HtmlCharacterEntityReferences.java @@ -23,6 +23,7 @@ import java.util.HashMap; import java.util.Map; import java.util.Properties; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -121,6 +122,7 @@ class HtmlCharacterEntityReferences { /** * Return the reference mapped to the given character or {@code null}. */ + @Nullable public String convertToReference(char character) { return convertToReference(character, WebUtils.DEFAULT_CHARACTER_ENCODING); } @@ -129,6 +131,7 @@ class HtmlCharacterEntityReferences { * Return the reference mapped to the given character or {@code null}. * @since 4.1.2 */ + @Nullable public String convertToReference(char character, String encoding) { if (encoding.startsWith("UTF-")){ switch (character){ diff --git a/spring-web/src/main/java/org/springframework/web/util/UriBuilder.java b/spring-web/src/main/java/org/springframework/web/util/UriBuilder.java index 2388d32581..1ffe300502 100644 --- a/spring-web/src/main/java/org/springframework/web/util/UriBuilder.java +++ b/spring-web/src/main/java/org/springframework/web/util/UriBuilder.java @@ -18,6 +18,7 @@ package org.springframework.web.util; import java.net.URI; import java.util.Map; +import org.springframework.lang.Nullable; import org.springframework.util.MultiValueMap; /** @@ -43,21 +44,21 @@ public interface UriBuilder { * and may also be {@code null} to clear the scheme of this builder. * @param scheme the URI scheme */ - UriBuilder scheme(String scheme); + UriBuilder scheme(@Nullable String scheme); /** * Set the URI user info which may contain URI template variables, and * may also be {@code null} to clear the user info of this builder. * @param userInfo the URI user info */ - UriBuilder userInfo(String userInfo); + UriBuilder userInfo(@Nullable String userInfo); /** * Set the URI host which may contain URI template variables, and may also * be {@code null} to clear the host of this builder. * @param host the URI host */ - UriBuilder host(String host); + UriBuilder host(@Nullable String host); /** * Set the URI port. Passing {@code -1} will clear the port of this builder. @@ -71,7 +72,7 @@ public interface UriBuilder { * Passing {@code null} will clear the port of this builder. * @param port the URI port */ - UriBuilder port(String port); + UriBuilder port(@Nullable String port); /** * Append the given path to the existing path of this builder. @@ -84,7 +85,7 @@ public interface UriBuilder { * Set the path of this builder overriding the existing path values. * @param path the URI path or {@code null} for an empty path. */ - UriBuilder replacePath(String path); + UriBuilder replacePath(@Nullable String path); /** * Append path segments to the existing path. Each path segment may contain @@ -113,7 +114,7 @@ public interface UriBuilder { * Set the query of this builder overriding all existing query parameters. * @param query the query string or {@code null} to remove all query params */ - UriBuilder replaceQuery(String query); + UriBuilder replaceQuery(@Nullable String query); /** * Append the given query parameter to the existing query parameters. The @@ -150,7 +151,7 @@ public interface UriBuilder { * and may also be {@code null} to clear the fragment of this builder. * @param fragment the URI fragment */ - UriBuilder fragment(String fragment); + UriBuilder fragment(@Nullable String fragment); /** * Build a {@link URI} instance and replaces URI template variables diff --git a/spring-web/src/main/java/org/springframework/web/util/UriComponents.java b/spring-web/src/main/java/org/springframework/web/util/UriComponents.java index 9ada40127a..1415ac8714 100644 --- a/spring-web/src/main/java/org/springframework/web/util/UriComponents.java +++ b/spring-web/src/main/java/org/springframework/web/util/UriComponents.java @@ -27,6 +27,7 @@ import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.MultiValueMap; @@ -65,6 +66,7 @@ public abstract class UriComponents implements Serializable { /** * Return the scheme. Can be {@code null}. */ + @Nullable public final String getScheme() { return this.scheme; } @@ -72,16 +74,19 @@ public abstract class UriComponents implements Serializable { /** * Return the scheme specific part. Can be {@code null}. */ + @Nullable public abstract String getSchemeSpecificPart(); /** * Return the user info. Can be {@code null}. */ + @Nullable public abstract String getUserInfo(); /** * Return the host. Can be {@code null}. */ + @Nullable public abstract String getHost(); /** @@ -92,6 +97,7 @@ public abstract class UriComponents implements Serializable { /** * Return the path. Can be {@code null}. */ + @Nullable public abstract String getPath(); /** @@ -102,6 +108,7 @@ public abstract class UriComponents implements Serializable { /** * Return the query. Can be {@code null}. */ + @Nullable public abstract String getQuery(); /** @@ -112,6 +119,7 @@ public abstract class UriComponents implements Serializable { /** * Return the fragment. Can be {@code null}. */ + @Nullable public final String getFragment() { return this.fragment; } @@ -279,7 +287,8 @@ public abstract class UriComponents implements Serializable { * @param name the variable name * @return the variable value, possibly {@code null} or {@link #SKIP_VALUE} */ - Object getValue(String name); + @Nullable + Object getValue(@Nullable String name); } diff --git a/spring-web/src/main/java/org/springframework/web/util/UriComponentsBuilder.java b/spring-web/src/main/java/org/springframework/web/util/UriComponentsBuilder.java index 255e0b30f8..c21c668e74 100644 --- a/spring-web/src/main/java/org/springframework/web/util/UriComponentsBuilder.java +++ b/spring-web/src/main/java/org/springframework/web/util/UriComponentsBuilder.java @@ -26,6 +26,7 @@ import java.util.regex.Pattern; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpRequest; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; @@ -454,7 +455,7 @@ public class UriComponentsBuilder implements UriBuilder, Cloneable { * @return this UriComponentsBuilder */ @Override - public UriComponentsBuilder scheme(String scheme) { + public UriComponentsBuilder scheme(@Nullable String scheme) { this.scheme = scheme; return this; } @@ -480,7 +481,7 @@ public class UriComponentsBuilder implements UriBuilder, Cloneable { * @return this UriComponentsBuilder */ @Override - public UriComponentsBuilder userInfo(String userInfo) { + public UriComponentsBuilder userInfo(@Nullable String userInfo) { this.userInfo = userInfo; resetSchemeSpecificPart(); return this; @@ -493,7 +494,7 @@ public class UriComponentsBuilder implements UriBuilder, Cloneable { * @return this UriComponentsBuilder */ @Override - public UriComponentsBuilder host(String host) { + public UriComponentsBuilder host(@Nullable String host) { this.host = host; resetSchemeSpecificPart(); return this; @@ -520,7 +521,7 @@ public class UriComponentsBuilder implements UriBuilder, Cloneable { * @return this UriComponentsBuilder */ @Override - public UriComponentsBuilder port(String port) { + public UriComponentsBuilder port(@Nullable String port) { this.port = port; resetSchemeSpecificPart(); return this; @@ -545,7 +546,7 @@ public class UriComponentsBuilder implements UriBuilder, Cloneable { * @return this UriComponentsBuilder */ @Override - public UriComponentsBuilder replacePath(String path) { + public UriComponentsBuilder replacePath(@Nullable String path) { this.pathBuilder = new CompositePathComponentBuilder(path); resetSchemeSpecificPart(); return this; @@ -605,7 +606,7 @@ public class UriComponentsBuilder implements UriBuilder, Cloneable { * @return this UriComponentsBuilder */ @Override - public UriComponentsBuilder replaceQuery(String query) { + public UriComponentsBuilder replaceQuery(@Nullable String query) { this.queryParams.clear(); query(query); resetSchemeSpecificPart(); @@ -691,7 +692,7 @@ public class UriComponentsBuilder implements UriBuilder, Cloneable { * @return this UriComponentsBuilder */ @Override - public UriComponentsBuilder fragment(String fragment) { + public UriComponentsBuilder fragment(@Nullable String fragment) { if (fragment != null) { Assert.hasLength(fragment, "Fragment must not be empty"); this.fragment = fragment; @@ -795,6 +796,7 @@ public class UriComponentsBuilder implements UriBuilder, Cloneable { private interface PathComponentBuilder { + @Nullable PathComponent build(); PathComponentBuilder cloneBuilder(); @@ -843,6 +845,7 @@ public class UriComponentsBuilder implements UriBuilder, Cloneable { } @SuppressWarnings("unchecked") + @Nullable private T getLastBuilder(Class builderClass) { if (!this.builders.isEmpty()) { PathComponentBuilder last = this.builders.getLast(); diff --git a/spring-web/src/main/java/org/springframework/web/util/UriUtils.java b/spring-web/src/main/java/org/springframework/web/util/UriUtils.java index 7fd64dc254..2144b74c70 100644 --- a/spring-web/src/main/java/org/springframework/web/util/UriUtils.java +++ b/spring-web/src/main/java/org/springframework/web/util/UriUtils.java @@ -24,6 +24,7 @@ import java.util.LinkedHashMap; import java.util.Map; import java.util.stream.Collectors; +import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; /** @@ -237,6 +238,7 @@ public abstract class UriUtils { * @return the extracted file extension (e.g. "html") * @since 4.3.2 */ + @Nullable public static String extractFileExtension(String path) { int end = path.indexOf('?'); if (end == -1) { diff --git a/spring-web/src/main/java/org/springframework/web/util/UrlPathHelper.java b/spring-web/src/main/java/org/springframework/web/util/UrlPathHelper.java index 42d3662d57..afc8038b3c 100644 --- a/spring-web/src/main/java/org/springframework/web/util/UrlPathHelper.java +++ b/spring-web/src/main/java/org/springframework/web/util/UrlPathHelper.java @@ -27,6 +27,7 @@ import javax.servlet.http.HttpServletRequest; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.lang.Nullable; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.util.StringUtils; @@ -238,6 +239,7 @@ public class UrlPathHelper { * context path and the servlet path returned by the HttpServletRequest are * stripped of semicolon content unlike the requesUri. */ + @Nullable private String getRemainingPath(String requestUri, String mapping, boolean ignoreCase) { int index1 = 0; int index2 = 0; diff --git a/spring-web/src/main/java/org/springframework/web/util/WebUtils.java b/spring-web/src/main/java/org/springframework/web/util/WebUtils.java index 28b7989347..29064ee33e 100644 --- a/spring-web/src/main/java/org/springframework/web/util/WebUtils.java +++ b/spring-web/src/main/java/org/springframework/web/util/WebUtils.java @@ -23,6 +23,7 @@ import java.util.Enumeration; import java.util.Map; import java.util.StringTokenizer; import java.util.TreeMap; + import javax.servlet.ServletContext; import javax.servlet.ServletRequest; import javax.servlet.ServletRequestWrapper; @@ -35,6 +36,7 @@ import javax.servlet.http.HttpSession; import org.springframework.http.HttpRequest; import org.springframework.http.server.ServletServerHttpRequest; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.util.LinkedMultiValueMap; @@ -191,6 +193,7 @@ public abstract class WebUtils { * @return whether default HTML escaping is enabled for the given application * ({@code null} = no explicit default) */ + @Nullable public static Boolean getDefaultHtmlEscape(ServletContext servletContext) { if (servletContext == null) { return null; @@ -213,6 +216,7 @@ public abstract class WebUtils { * ({@code null} = no explicit default) * @since 4.1.2 */ + @Nullable public static Boolean getResponseEncodedHtmlEscape(ServletContext servletContext) { if (servletContext == null) { return null; @@ -265,6 +269,7 @@ public abstract class WebUtils { * @param request current HTTP request * @return the session id, or {@code null} if none */ + @Nullable public static String getSessionId(HttpServletRequest request) { Assert.notNull(request, "Request must not be null"); HttpSession session = request.getSession(false); @@ -279,6 +284,7 @@ public abstract class WebUtils { * @param name the name of the session attribute * @return the value of the session attribute, or {@code null} if not found */ + @Nullable public static Object getSessionAttribute(HttpServletRequest request, String name) { Assert.notNull(request, "Request must not be null"); HttpSession session = request.getSession(false); @@ -294,6 +300,7 @@ public abstract class WebUtils { * @return the value of the session attribute, or {@code null} if not found * @throws IllegalStateException if the session attribute could not be found */ + @Nullable public static Object getRequiredSessionAttribute(HttpServletRequest request, String name) throws IllegalStateException { @@ -364,6 +371,7 @@ public abstract class WebUtils { * of that type is available */ @SuppressWarnings("unchecked") + @Nullable public static T getNativeRequest(ServletRequest request, Class requiredType) { if (requiredType != null) { if (requiredType.isInstance(request)) { @@ -385,6 +393,7 @@ public abstract class WebUtils { * of that type is available */ @SuppressWarnings("unchecked") + @Nullable public static T getNativeResponse(ServletResponse response, Class requiredType) { if (requiredType != null) { if (requiredType.isInstance(response)) { @@ -476,6 +485,7 @@ public abstract class WebUtils { * @param name cookie name * @return the first cookie with the given name, or {@code null} if none is found */ + @Nullable public static Cookie getCookie(HttpServletRequest request, String name) { Assert.notNull(request, "Request must not be null"); Cookie cookies[] = request.getCookies(); @@ -520,6 +530,7 @@ public abstract class WebUtils { * @return the value of the parameter, or {@code null} * if the parameter does not exist in given request */ + @Nullable public static String findParameterValue(ServletRequest request, String name) { return findParameterValue(request.getParameterMap(), name); } @@ -547,6 +558,7 @@ public abstract class WebUtils { * @return the value of the parameter, or {@code null} * if the parameter does not exist in given request */ + @Nullable public static String findParameterValue(Map parameters, String name) { // First try to get it as a normal name=value parameter Object value = parameters.get(name); diff --git a/spring-web/src/main/java/org/springframework/web/util/package-info.java b/spring-web/src/main/java/org/springframework/web/util/package-info.java index 42edc4aebf..58b9295163 100644 --- a/spring-web/src/main/java/org/springframework/web/util/package-info.java +++ b/spring-web/src/main/java/org/springframework/web/util/package-info.java @@ -2,4 +2,7 @@ * Miscellaneous web utility classes, such as HTML escaping, * Log4j initialization, and cookie handling. */ +@NonNullApi package org.springframework.web.util; + +import org.springframework.lang.NonNullApi; diff --git a/spring-web/src/main/java/org/springframework/web/util/pattern/PathPattern.java b/spring-web/src/main/java/org/springframework/web/util/pattern/PathPattern.java index 9c17ce6796..919782b8ec 100644 --- a/spring-web/src/main/java/org/springframework/web/util/pattern/PathPattern.java +++ b/spring-web/src/main/java/org/springframework/web/util/pattern/PathPattern.java @@ -20,6 +20,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.Map; +import org.springframework.lang.Nullable; import org.springframework.util.PathMatcher; import static org.springframework.util.StringUtils.*; @@ -173,6 +174,7 @@ public class PathPattern implements Comparable { * @return a {@link PathRemainingMatchInfo} describing the match result or null if * the path does not match this pattern */ + @Nullable public PathRemainingMatchInfo getPathRemaining(String path) { if (this.head == null) { if (path == null) { diff --git a/spring-web/src/main/java/org/springframework/web/util/pattern/package-info.java b/spring-web/src/main/java/org/springframework/web/util/pattern/package-info.java index ad083bec05..29e42f9425 100644 --- a/spring-web/src/main/java/org/springframework/web/util/pattern/package-info.java +++ b/spring-web/src/main/java/org/springframework/web/util/pattern/package-info.java @@ -1,4 +1,7 @@ /** * Spring's path pattern parser/matcher. */ +@NonNullApi package org.springframework.web.util.pattern; + +import org.springframework.lang.NonNullApi; diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/BindingContext.java b/spring-webflux/src/main/java/org/springframework/web/reactive/BindingContext.java index d6e1f986fc..d3f950b311 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/BindingContext.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/BindingContext.java @@ -16,6 +16,7 @@ package org.springframework.web.reactive; +import org.springframework.lang.Nullable; import org.springframework.ui.Model; import org.springframework.validation.support.BindingAwareConcurrentModel; import org.springframework.web.bind.support.WebBindingInitializer; @@ -52,7 +53,7 @@ public class BindingContext { * Create a new {@code BindingContext} with the given initializer. * @param initializer the binding initializer to apply (may be {@code null}) */ - public BindingContext(WebBindingInitializer initializer) { + public BindingContext(@Nullable WebBindingInitializer initializer) { this.initializer = initializer; } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/HandlerResult.java b/spring-webflux/src/main/java/org/springframework/web/reactive/HandlerResult.java index 6e661b9be7..90d0576ff1 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/HandlerResult.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/HandlerResult.java @@ -22,6 +22,7 @@ import reactor.core.publisher.Mono; import org.springframework.core.MethodParameter; import org.springframework.core.ResolvableType; +import org.springframework.lang.Nullable; import org.springframework.ui.Model; import org.springframework.util.Assert; @@ -50,7 +51,7 @@ public class HandlerResult { * @param returnValue the return value from the handler possibly {@code null} * @param returnType the return value type */ - public HandlerResult(Object handler, Object returnValue, MethodParameter returnType) { + public HandlerResult(Object handler, @Nullable Object returnValue, MethodParameter returnType) { this(handler, returnValue, returnType, null); } @@ -61,7 +62,7 @@ public class HandlerResult { * @param returnType the return value type * @param context the binding context used for request handling */ - public HandlerResult(Object handler, Object returnValue, MethodParameter returnType, + public HandlerResult(Object handler, @Nullable Object returnValue, MethodParameter returnType, BindingContext context) { Assert.notNull(handler, "'handler' is required"); @@ -83,6 +84,7 @@ public class HandlerResult { /** * Return the value returned from the handler, if any. */ + @Nullable public Object getReturnValue() { return this.returnValue; } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/accept/AbstractMappingContentTypeResolver.java b/spring-webflux/src/main/java/org/springframework/web/reactive/accept/AbstractMappingContentTypeResolver.java index bd38fac63f..2dc0a9229f 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/accept/AbstractMappingContentTypeResolver.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/accept/AbstractMappingContentTypeResolver.java @@ -25,6 +25,7 @@ import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import org.springframework.http.MediaType; +import org.springframework.lang.Nullable; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.util.StringUtils; @@ -73,6 +74,7 @@ public abstract class AbstractMappingContentTypeResolver implements MappingConte * @param key the key converted to lower case * @return a MediaType or {@code null} */ + @Nullable protected MediaType getMediaType(String key) { return this.mediaTypeLookup.get(key.toLowerCase(Locale.ENGLISH)); } @@ -125,6 +127,7 @@ public abstract class AbstractMappingContentTypeResolver implements MappingConte * e.g. file extension, query parameter, etc. * @return the key or {@code null} */ + @Nullable protected abstract String extractKey(ServerWebExchange exchange); /** @@ -141,6 +144,7 @@ public abstract class AbstractMappingContentTypeResolver implements MappingConte * this method it will be added to the mappings. */ @SuppressWarnings("UnusedParameters") + @Nullable protected MediaType handleNoMatch(String key) throws NotAcceptableStatusException { return null; } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/accept/CompositeContentTypeResolver.java b/spring-webflux/src/main/java/org/springframework/web/reactive/accept/CompositeContentTypeResolver.java index 745ed19174..423653438d 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/accept/CompositeContentTypeResolver.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/accept/CompositeContentTypeResolver.java @@ -22,6 +22,7 @@ import java.util.List; import java.util.Set; import org.springframework.http.MediaType; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.server.NotAcceptableStatusException; import org.springframework.web.server.ServerWebExchange; @@ -61,6 +62,7 @@ public class CompositeContentTypeResolver implements MappingContentTypeResolver * @return the first matching resolver or {@code null}. */ @SuppressWarnings("unchecked") + @Nullable public T findResolver(Class resolverType) { for (RequestedContentTypeResolver resolver : this.resolvers) { if (resolverType.isInstance(resolver)) { diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/accept/PathExtensionContentTypeResolver.java b/spring-webflux/src/main/java/org/springframework/web/reactive/accept/PathExtensionContentTypeResolver.java index 7ad79e0383..b7c1b7e49e 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/accept/PathExtensionContentTypeResolver.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/accept/PathExtensionContentTypeResolver.java @@ -23,6 +23,7 @@ import java.util.Optional; import org.springframework.core.io.Resource; import org.springframework.http.MediaType; import org.springframework.http.MediaTypeFactory; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.StringUtils; import org.springframework.web.server.NotAcceptableStatusException; @@ -110,6 +111,7 @@ public class PathExtensionContentTypeResolver extends AbstractMappingContentType * @param resource the resource * @return the MediaType for the extension, or {@code null} if none determined */ + @Nullable public MediaType resolveMediaTypeForResource(Resource resource) { Assert.notNull(resource, "Resource must not be null"); MediaType mediaType = null; diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/accept/package-info.java b/spring-webflux/src/main/java/org/springframework/web/reactive/accept/package-info.java index 0f06c119a0..498eca8b8c 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/accept/package-info.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/accept/package-info.java @@ -3,4 +3,7 @@ * strategy and implementations to resolve the requested content type for a * given request. */ +@NonNullApi package org.springframework.web.reactive.accept; + +import org.springframework.lang.NonNullApi; diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/config/ResourceHandlerRegistry.java b/spring-webflux/src/main/java/org/springframework/web/reactive/config/ResourceHandlerRegistry.java index 640dd1152a..d9b927c125 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/config/ResourceHandlerRegistry.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/config/ResourceHandlerRegistry.java @@ -24,6 +24,7 @@ import java.util.Map; import org.springframework.beans.factory.BeanInitializationException; import org.springframework.context.ApplicationContext; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.reactive.accept.CompositeContentTypeResolver; import org.springframework.web.reactive.handler.AbstractHandlerMapping; @@ -127,6 +128,7 @@ public class ResourceHandlerRegistry { * Return a handler mapping with the mapped resource handlers; or {@code null} in case * of no registrations. */ + @Nullable protected AbstractHandlerMapping getHandlerMapping() { if (this.registrations.isEmpty()) { return null; diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/config/WebFluxConfigurationSupport.java b/spring-webflux/src/main/java/org/springframework/web/reactive/config/WebFluxConfigurationSupport.java index e1eb5d1e26..f0ebd8669f 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/config/WebFluxConfigurationSupport.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/config/WebFluxConfigurationSupport.java @@ -36,6 +36,7 @@ import org.springframework.format.support.DefaultFormattingConversionService; import org.springframework.format.support.FormattingConversionService; import org.springframework.http.MediaType; import org.springframework.http.codec.ServerCodecConfigurer; +import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.validation.Errors; import org.springframework.validation.MessageCodesResolver; @@ -373,6 +374,7 @@ public class WebFluxConfigurationSupport implements ApplicationContextAware { /** * Override this method to provide a custom {@link Validator}. */ + @Nullable protected Validator getValidator() { return null; } @@ -380,6 +382,7 @@ public class WebFluxConfigurationSupport implements ApplicationContextAware { /** * Override this method to provide a custom {@link MessageCodesResolver}. */ + @Nullable protected MessageCodesResolver getMessageCodesResolver() { return null; } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/config/WebFluxConfigurer.java b/spring-webflux/src/main/java/org/springframework/web/reactive/config/WebFluxConfigurer.java index 71bd17bea2..43519bdc69 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/config/WebFluxConfigurer.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/config/WebFluxConfigurer.java @@ -20,6 +20,7 @@ import org.springframework.core.convert.converter.Converter; import org.springframework.format.Formatter; import org.springframework.format.FormatterRegistry; import org.springframework.http.codec.ServerCodecConfigurer; +import org.springframework.lang.Nullable; import org.springframework.validation.MessageCodesResolver; import org.springframework.validation.Validator; import org.springframework.web.reactive.accept.CompositeContentTypeResolver; @@ -102,6 +103,7 @@ public interface WebFluxConfigurer { *

    By default a validator for standard bean validation is created if * bean validation api is present on the classpath. */ + @Nullable default Validator getValidator() { return null; } @@ -110,6 +112,7 @@ public interface WebFluxConfigurer { * Provide a custom {@link MessageCodesResolver} to use for data binding instead * of the one created by default in {@link org.springframework.validation.DataBinder}. */ + @Nullable default MessageCodesResolver getMessageCodesResolver() { return null; } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/config/WebFluxConfigurerComposite.java b/spring-webflux/src/main/java/org/springframework/web/reactive/config/WebFluxConfigurerComposite.java index 67bab03662..18e125894d 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/config/WebFluxConfigurerComposite.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/config/WebFluxConfigurerComposite.java @@ -23,6 +23,7 @@ import java.util.stream.Collectors; import org.springframework.format.FormatterRegistry; import org.springframework.http.codec.ServerCodecConfigurer; +import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; import org.springframework.validation.MessageCodesResolver; import org.springframework.validation.Validator; @@ -98,6 +99,7 @@ public class WebFluxConfigurerComposite implements WebFluxConfigurer { this.delegates.forEach(delegate -> delegate.configureViewResolvers(registry)); } + @Nullable private T createSingleBean(Function factory, Class beanType) { List result = this.delegates.stream().map(factory).filter(t -> t != null).collect(Collectors.toList()); if (result.isEmpty()) { diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/config/package-info.java b/spring-webflux/src/main/java/org/springframework/web/reactive/config/package-info.java index 0f0516b227..03cf147d9c 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/config/package-info.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/config/package-info.java @@ -1,4 +1,7 @@ /** * Spring WebFlux configuration infrastructure. */ +@NonNullApi package org.springframework.web.reactive.config; + +import org.springframework.lang.NonNullApi; diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/UnsupportedMediaTypeException.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/UnsupportedMediaTypeException.java index 5cc0a5cc77..d28e9f28dd 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/UnsupportedMediaTypeException.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/UnsupportedMediaTypeException.java @@ -18,10 +18,10 @@ package org.springframework.web.reactive.function; import java.util.Collections; import java.util.List; -import java.util.Optional; import org.springframework.core.NestedRuntimeException; import org.springframework.http.MediaType; +import org.springframework.lang.Nullable; /** * Exception thrown to indicate that a {@code Content-Type} is not supported. @@ -60,6 +60,7 @@ public class UnsupportedMediaTypeException extends NestedRuntimeException { * Return the request Content-Type header if it was parsed successfully, * or {@code null} otherwise. */ + @Nullable public MediaType getContentType() { return this.contentType; } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClient.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClient.java index 3ffd01a33b..91f3707c2d 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClient.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClient.java @@ -37,6 +37,7 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.http.client.reactive.ClientHttpRequest; import org.springframework.http.client.reactive.ClientHttpResponse; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.util.LinkedMultiValueMap; @@ -297,6 +298,7 @@ class DefaultWebClient implements WebClient { return ClientRequest.method(this.httpMethod, this.uri).headers(initHeaders()).cookies(initCookies()); } + @Nullable private HttpHeaders initHeaders() { if (CollectionUtils.isEmpty(defaultHeaders) && CollectionUtils.isEmpty(this.headers)) { return null; @@ -319,6 +321,7 @@ class DefaultWebClient implements WebClient { } } + @Nullable private MultiValueMap initCookies() { if (CollectionUtils.isEmpty(defaultCookies) && CollectionUtils.isEmpty(this.cookies)) { return null; diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/package-info.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/package-info.java index 57e61fc9ce..807c9ef453 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/package-info.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/package-info.java @@ -3,4 +3,7 @@ * that builds on top of the * {@code org.springframework.http.client.reactive} reactive HTTP adapter layer. */ +@NonNullApi package org.springframework.web.reactive.function.client; + +import org.springframework.lang.NonNullApi; diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/package-info.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/package-info.java index b145d8dea2..7a6dd1f8e1 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/package-info.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/package-info.java @@ -1,4 +1,7 @@ /** * Provides a foundation for both the reactive client and server subpackages. */ -package org.springframework.web.reactive.function; \ No newline at end of file +@NonNullApi +package org.springframework.web.reactive.function; + +import org.springframework.lang.NonNullApi; diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/RenderingResponse.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/RenderingResponse.java index b6127f31f0..56773870e8 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/RenderingResponse.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/RenderingResponse.java @@ -23,6 +23,7 @@ import reactor.core.publisher.Mono; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -92,7 +93,7 @@ public interface RenderingResponse extends ServerResponse { * @param name the name of the model attribute (never {@code null}) * @param value the model attribute value (can be {@code null}) */ - Builder modelAttribute(String name, Object value); + Builder modelAttribute(String name, @Nullable Object value); /** * Copy all attributes in the supplied array into the model, diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/package-info.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/package-info.java index d6343b3fae..fefa003478 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/package-info.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/package-info.java @@ -1,4 +1,7 @@ /** * Provides the types that make up Spring's functional web framework. */ -package org.springframework.web.reactive.function.server; \ No newline at end of file +@NonNullApi +package org.springframework.web.reactive.function.server; + +import org.springframework.lang.NonNullApi; diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/support/package-info.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/support/package-info.java index a9507adcb3..fa7cd76c92 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/support/package-info.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/support/package-info.java @@ -4,4 +4,7 @@ * a {@code HandlerResultHandler} that supports {@code ServerResponse}s, and * a {@code ServerRequest} wrapper to adapt a request. */ -package org.springframework.web.reactive.function.server.support; \ No newline at end of file +@NonNullApi +package org.springframework.web.reactive.function.server.support; + +import org.springframework.lang.NonNullApi; diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/handler/AbstractHandlerMapping.java b/spring-webflux/src/main/java/org/springframework/web/reactive/handler/AbstractHandlerMapping.java index a1fcb23524..d2a20b0bef 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/handler/AbstractHandlerMapping.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/handler/AbstractHandlerMapping.java @@ -22,6 +22,7 @@ import reactor.core.publisher.Mono; import org.springframework.context.support.ApplicationObjectSupport; import org.springframework.core.Ordered; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.PathMatcher; import org.springframework.web.cors.CorsConfiguration; @@ -189,6 +190,7 @@ public abstract class AbstractHandlerMapping extends ApplicationObjectSupport im * @param exchange the current exchange * @return the CORS configuration for the handler, or {@code null} if none */ + @Nullable protected CorsConfiguration getCorsConfiguration(Object handler, ServerWebExchange exchange) { if (handler instanceof CorsConfigurationSource) { return ((CorsConfigurationSource) handler).getCorsConfiguration(exchange); diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/handler/AbstractUrlHandlerMapping.java b/spring-webflux/src/main/java/org/springframework/web/reactive/handler/AbstractUrlHandlerMapping.java index 7c5bbd5baa..4458bb34c6 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/handler/AbstractUrlHandlerMapping.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/handler/AbstractUrlHandlerMapping.java @@ -26,6 +26,7 @@ import java.util.Map; import reactor.core.publisher.Mono; import org.springframework.beans.BeansException; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.server.ServerWebExchange; @@ -129,6 +130,7 @@ public abstract class AbstractUrlHandlerMapping extends AbstractHandlerMapping { * @return the associated handler instance, or {@code null} if not found * @see org.springframework.web.util.pattern.ParsingPathMatcher */ + @Nullable protected Object lookupHandler(String urlPath, ServerWebExchange exchange) throws Exception { // Direct match? Object handler = this.handlerMap.get(urlPath); diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/handler/package-info.java b/spring-webflux/src/main/java/org/springframework/web/reactive/handler/package-info.java index 13c9d9aec7..94524fb665 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/handler/package-info.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/handler/package-info.java @@ -1,4 +1,7 @@ /** * Provides HandlerMapping implementations including abstract base classes. */ +@NonNullApi package org.springframework.web.reactive.handler; + +import org.springframework.lang.NonNullApi; diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/package-info.java b/spring-webflux/src/main/java/org/springframework/web/reactive/package-info.java index 51c980da9c..55bd9d94b9 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/package-info.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/package-info.java @@ -9,4 +9,7 @@ * routing and handling. The module also contains a functional, reactive * {@code WebClient} as well as client and server, reactive WebSocket support. */ +@NonNullApi package org.springframework.web.reactive; + +import org.springframework.lang.NonNullApi; diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/DefaultResourceResolverChain.java b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/DefaultResourceResolverChain.java index 6c051a96bd..0f049dc33c 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/DefaultResourceResolverChain.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/DefaultResourceResolverChain.java @@ -22,6 +22,7 @@ import java.util.List; import reactor.core.publisher.Mono; import org.springframework.core.io.Resource; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.server.ServerWebExchange; @@ -78,6 +79,7 @@ class DefaultResourceResolverChain implements ResourceResolverChain { } } + @Nullable private ResourceResolver getNext() { Assert.state(this.index <= this.resolvers.size(), "Current index exceeds the number of configured ResourceResolvers"); diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/DefaultResourceTransformerChain.java b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/DefaultResourceTransformerChain.java index f883026deb..b51cdd8054 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/DefaultResourceTransformerChain.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/DefaultResourceTransformerChain.java @@ -22,6 +22,7 @@ import java.util.List; import reactor.core.publisher.Mono; import org.springframework.core.io.Resource; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.server.ServerWebExchange; @@ -71,6 +72,7 @@ class DefaultResourceTransformerChain implements ResourceTransformerChain { } } + @Nullable private ResourceTransformer getNext() { Assert.state(this.index <= this.transformers.size(), "Current index exceeds the number of configured ResourceTransformer's"); diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/PathResourceResolver.java b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/PathResourceResolver.java index f3d61c7d3c..8860b53e06 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/PathResourceResolver.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/PathResourceResolver.java @@ -100,7 +100,7 @@ public class PathResourceResolver extends AbstractResourceResolver { * {@code Resource} for the given path relative to the location. * @param resourcePath the path to the resource * @param location the location to check - * @return the resource, or {@code null} if none found + * @return the resource, or empty {@link Mono} if none found */ protected Mono getResource(String resourcePath, Resource location) { try { diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/ResourceTransformer.java b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/ResourceTransformer.java index ec1130fb93..17a2e7c5ad 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/ResourceTransformer.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/ResourceTransformer.java @@ -35,7 +35,7 @@ public interface ResourceTransformer { * @param exchange the current exchange * @param resource the resource to transform * @param transformerChain the chain of remaining transformers to delegate to - * @return the transformed resource (never {@code null}) + * @return the transformed resource (never empty) */ Mono transform(ServerWebExchange exchange, Resource resource, ResourceTransformerChain transformerChain); diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/ResourceTransformerChain.java b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/ResourceTransformerChain.java index 1d2fd737cc..184d6107b1 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/ResourceTransformerChain.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/ResourceTransformerChain.java @@ -41,7 +41,7 @@ public interface ResourceTransformerChain { * Transform the given resource. * @param exchange the current exchange * @param resource the candidate resource to transform - * @return the transformed or the same resource, never {@code null} + * @return the transformed or the same resource, never empty */ Mono transform(ServerWebExchange exchange, Resource resource); diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/ResourceTransformerSupport.java b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/ResourceTransformerSupport.java index 287896f42d..fbeb9bcc9a 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/ResourceTransformerSupport.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/ResourceTransformerSupport.java @@ -66,7 +66,7 @@ public abstract class ResourceTransformerSupport implements ResourceTransformer * @param exchange the current exchange * @param resource the resource being transformed * @param transformerChain the transformer chain - * @return the resolved URL or null + * @return the resolved URL or an empty {@link Mono} */ protected Mono resolveUrlPath(String resourcePath, ServerWebExchange exchange, Resource resource, ResourceTransformerChain transformerChain) { diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/ResourceUrlProvider.java b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/ResourceUrlProvider.java index 26cf7f6aae..b3ef7234bd 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/ResourceUrlProvider.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/ResourceUrlProvider.java @@ -167,7 +167,7 @@ public class ResourceUrlProvider implements ApplicationListener getForRequestUrl(ServerWebExchange exchange, String requestUrl) { if (logger.isTraceEnabled()) { @@ -211,7 +211,7 @@ public class ResourceUrlProvider implements ApplicationListenerIf several handler mappings match, the handler used will be the one * configured with the most specific pattern. * @param lookupPath the lookup path to check - * @return the resolved public URL path, or {@code null} if unresolved + * @return the resolved public URL path, or empty if unresolved */ public final Mono getForLookupPath(String lookupPath) { if (logger.isTraceEnabled()) { diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/ResourceWebHandler.java b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/ResourceWebHandler.java index db42c513e8..a874998a56 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/ResourceWebHandler.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/ResourceWebHandler.java @@ -44,6 +44,7 @@ import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.codec.ResourceHttpMessageWriter; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.util.ObjectUtils; @@ -473,6 +474,7 @@ public class ResourceWebHandler * @param resource the resource to check * @return the corresponding media type, or {@code null} if none found */ + @Nullable protected MediaType getMediaType(ServerWebExchange exchange, Resource resource) { return this.pathExtensionResolver.resolveMediaTypeForResource(resource); } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/VersionPathStrategy.java b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/VersionPathStrategy.java index c522c6901e..28d245b45c 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/VersionPathStrategy.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/VersionPathStrategy.java @@ -16,6 +16,8 @@ package org.springframework.web.reactive.resource; +import org.springframework.lang.Nullable; + /** * A strategy for extracting and embedding a resource version in its URL path. * @@ -30,6 +32,7 @@ public interface VersionPathStrategy { * @param requestPath the request path to check * @return the version string or {@code null} if none was found */ + @Nullable String extractVersion(String requestPath); /** diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/VersionResourceResolver.java b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/VersionResourceResolver.java index a4c2634302..148963662f 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/VersionResourceResolver.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/VersionResourceResolver.java @@ -34,6 +34,7 @@ import reactor.core.publisher.Mono; import org.springframework.core.io.AbstractResource; import org.springframework.core.io.Resource; import org.springframework.http.HttpHeaders; +import org.springframework.lang.Nullable; import org.springframework.util.AntPathMatcher; import org.springframework.util.StringUtils; import org.springframework.web.server.ServerWebExchange; @@ -235,6 +236,7 @@ public class VersionResourceResolver extends AbstractResourceResolver { * Find a {@code VersionStrategy} for the request path of the requested resource. * @return an instance of a {@code VersionStrategy} or null if none matches that request path */ + @Nullable protected VersionStrategy getStrategyForPath(String requestPath) { String path = "/".concat(requestPath); List matchingPatterns = new ArrayList<>(); diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/VersionStrategy.java b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/VersionStrategy.java index 51d500702c..5b328cfa98 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/VersionStrategy.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/VersionStrategy.java @@ -17,6 +17,7 @@ package org.springframework.web.reactive.resource; import org.springframework.core.io.Resource; +import org.springframework.lang.Nullable; /** * An extension of {@link VersionPathStrategy} that adds a method @@ -34,6 +35,7 @@ public interface VersionStrategy extends VersionPathStrategy { * @param resource the resource to check * @return the version (never {@code null}) */ + @Nullable String getResourceVersion(Resource resource); } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/WebJarsResourceResolver.java b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/WebJarsResourceResolver.java index 710ba37ec2..971090ea53 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/WebJarsResourceResolver.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/WebJarsResourceResolver.java @@ -23,6 +23,7 @@ import org.webjars.WebJarAssetLocator; import reactor.core.publisher.Mono; import org.springframework.core.io.Resource; +import org.springframework.lang.Nullable; import org.springframework.web.server.ServerWebExchange; /** @@ -102,6 +103,7 @@ public class WebJarsResourceResolver extends AbstractResourceResolver { })); } + @Nullable protected String findWebJarResourcePath(String path) { try { int startOffset = (path.startsWith("/") ? 1 : 0); diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/package-info.java b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/package-info.java index a97c4fe9b8..1b4c914d2c 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/package-info.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/package-info.java @@ -1,4 +1,7 @@ /** * Support classes for serving static resources. */ +@NonNullApi package org.springframework.web.reactive.resource; + +import org.springframework.lang.NonNullApi; diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/HandlerResultHandlerSupport.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/HandlerResultHandlerSupport.java index a4652125c3..110957bc2c 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/HandlerResultHandlerSupport.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/HandlerResultHandlerSupport.java @@ -28,6 +28,7 @@ import org.springframework.core.Ordered; import org.springframework.core.ReactiveAdapter; import org.springframework.core.ReactiveAdapterRegistry; import org.springframework.http.MediaType; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.reactive.HandlerMapping; import org.springframework.web.reactive.HandlerResult; @@ -98,6 +99,7 @@ public abstract class HandlerResultHandlerSupport implements Ordered { * Get a {@code ReactiveAdapter} for the top-level return value type. * @return the matching adapter or {@code null} */ + @Nullable protected ReactiveAdapter getAdapter(HandlerResult result) { Class returnType = result.getReturnType().getRawClass(); return getAdapterRegistry().getAdapter(returnType, result.getReturnValue()); @@ -110,6 +112,7 @@ public abstract class HandlerResultHandlerSupport implements Ordered { * @param producibleTypesSupplier the media types that can be produced for the current request * @return the selected media type or {@code null} */ + @Nullable protected MediaType selectMediaType(ServerWebExchange exchange, Supplier> producibleTypesSupplier) { diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/CompositeRequestCondition.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/CompositeRequestCondition.java index 66b77d264a..8d0f4df2e4 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/CompositeRequestCondition.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/CompositeRequestCondition.java @@ -21,6 +21,7 @@ import java.util.Collection; import java.util.Collections; import java.util.List; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; import org.springframework.web.server.ServerWebExchange; @@ -49,7 +50,7 @@ public class CompositeRequestCondition extends AbstractRequestCondition... requestConditions) { + public CompositeRequestCondition(@Nullable RequestCondition... requestConditions) { this.requestConditions = wrap(requestConditions); } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/RequestCondition.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/RequestCondition.java index e90b4b2870..8ddda6b7b8 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/RequestCondition.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/RequestCondition.java @@ -16,6 +16,7 @@ package org.springframework.web.reactive.result.condition; +import org.springframework.lang.Nullable; import org.springframework.web.server.ServerWebExchange; /** @@ -55,6 +56,7 @@ public interface RequestCondition { * empty content thus not causing a failure to match. * @return a condition instance in case of a match or {@code null} otherwise. */ + @Nullable T getMatchingCondition(ServerWebExchange exchange); /** diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/RequestConditionHolder.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/RequestConditionHolder.java index 9f5f4ace90..9d2e882af9 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/RequestConditionHolder.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/RequestConditionHolder.java @@ -19,6 +19,7 @@ package org.springframework.web.reactive.result.condition; import java.util.Collection; import java.util.Collections; +import org.springframework.lang.Nullable; import org.springframework.web.server.ServerWebExchange; /** @@ -45,7 +46,7 @@ public final class RequestConditionHolder extends AbstractRequestCondition requestCondition) { + public RequestConditionHolder(@Nullable RequestCondition requestCondition) { this.condition = (RequestCondition) requestCondition; } @@ -53,6 +54,7 @@ public final class RequestConditionHolder extends AbstractRequestCondition getCondition() { return this.condition; } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/AbstractHandlerMethodMapping.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/AbstractHandlerMethodMapping.java index 2f0f41d89f..9585e19b18 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/AbstractHandlerMethodMapping.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/AbstractHandlerMethodMapping.java @@ -34,6 +34,7 @@ import reactor.core.publisher.Mono; import org.springframework.aop.support.AopUtils; import org.springframework.beans.factory.InitializingBean; import org.springframework.core.MethodIntrospector; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.LinkedMultiValueMap; @@ -233,6 +234,7 @@ public abstract class AbstractHandlerMethodMapping extends AbstractHandlerMap /** * Extract and return the CORS configuration for the mapping. */ + @Nullable protected CorsConfiguration initCorsConfiguration(Object handler, Method method, T mapping) { return null; } @@ -293,6 +295,7 @@ public abstract class AbstractHandlerMethodMapping extends AbstractHandlerMap * @see #handleMatch(Object, String, ServerWebExchange) * @see #handleNoMatch(Set, String, ServerWebExchange) */ + @Nullable protected HandlerMethod lookupHandlerMethod(String lookupPath, ServerWebExchange exchange) throws Exception { @@ -360,6 +363,7 @@ public abstract class AbstractHandlerMethodMapping extends AbstractHandlerMap * @return an alternative HandlerMethod or {@code null} * @throws Exception provides details that can be translated into an error status code */ + @Nullable protected HandlerMethod handleNoMatch(Set mappings, String lookupPath, ServerWebExchange exchange) throws Exception { @@ -398,6 +402,7 @@ public abstract class AbstractHandlerMethodMapping extends AbstractHandlerMap * declaring class * @return the mapping, or {@code null} if the method is not mapped */ + @Nullable protected abstract T getMappingForMethod(Method method, Class handlerType); /** @@ -412,6 +417,7 @@ public abstract class AbstractHandlerMethodMapping extends AbstractHandlerMap * @param exchange the current exchange * @return the match, or {@code null} if the mapping doesn't match */ + @Nullable protected abstract T getMatchingMapping(T mapping, ServerWebExchange exchange); /** @@ -420,6 +426,7 @@ public abstract class AbstractHandlerMethodMapping extends AbstractHandlerMap * @param exchange the current exchange * @return the comparator (never {@code null}) */ + @Nullable protected abstract Comparator getMappingComparator(ServerWebExchange exchange); diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/RequestMappingInfo.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/RequestMappingInfo.java index 6dfe57170a..3741b94a45 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/RequestMappingInfo.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/RequestMappingInfo.java @@ -18,6 +18,7 @@ package org.springframework.web.reactive.result.method; import java.util.Set; +import org.springframework.lang.Nullable; import org.springframework.util.PathMatcher; import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.RequestMethod; @@ -104,6 +105,7 @@ public final class RequestMappingInfo implements RequestCondition getCustomCondition() { return this.customConditionHolder.getCondition(); } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractMessageReaderArgumentResolver.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractMessageReaderArgumentResolver.java index e93d9f6d0c..03a84688bd 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractMessageReaderArgumentResolver.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractMessageReaderArgumentResolver.java @@ -36,6 +36,7 @@ import org.springframework.http.MediaType; import org.springframework.http.codec.HttpMessageReader; import org.springframework.http.server.reactive.ServerHttpRequest; import org.springframework.http.server.reactive.ServerHttpResponse; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.validation.Validator; import org.springframework.validation.annotation.Validated; @@ -168,6 +169,7 @@ public abstract class AbstractMessageReaderArgumentResolver extends HandlerMetho * a (possibly empty) Object[] with validation hints. A return value of * {@code null} indicates that validation is not required. */ + @Nullable private Object[] extractValidationHints(MethodParameter parameter) { Annotation[] annotations = parameter.getParameterAnnotations(); for (Annotation ann : annotations) { diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractNamedValueArgumentResolver.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractNamedValueArgumentResolver.java index 28eb13e067..0fee528817 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractNamedValueArgumentResolver.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractNamedValueArgumentResolver.java @@ -28,6 +28,7 @@ import org.springframework.beans.factory.config.BeanExpressionResolver; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.core.MethodParameter; import org.springframework.core.ReactiveAdapterRegistry; +import org.springframework.lang.Nullable; import org.springframework.ui.Model; import org.springframework.web.bind.WebDataBinder; import org.springframework.web.bind.annotation.ValueConstants; @@ -72,7 +73,7 @@ public abstract class AbstractNamedValueArgumentResolver extends HandlerMethodAr * values are not expected to contain expressions * @param registry for checking reactive type wrappers */ - public AbstractNamedValueArgumentResolver(ConfigurableBeanFactory factory, ReactiveAdapterRegistry registry) { + public AbstractNamedValueArgumentResolver(@Nullable ConfigurableBeanFactory factory, ReactiveAdapterRegistry registry) { super(registry); this.configurableBeanFactory = factory; this.expressionContext = (factory != null ? new BeanExpressionContext(factory, null) : null); @@ -169,7 +170,7 @@ public abstract class AbstractNamedValueArgumentResolver extends HandlerMethodAr * @param parameter the method parameter to resolve to an argument value * (pre-nested in case of a {@link java.util.Optional} declaration) * @param exchange the current exchange - * @return the resolved argument (may be {@code null}) + * @return the resolved argument (may be empty {@link Mono}) */ protected abstract Mono resolveName(String name, MethodParameter parameter, ServerWebExchange exchange); @@ -248,7 +249,7 @@ public abstract class AbstractNamedValueArgumentResolver extends HandlerMethodAr * A {@code null} results in a {@code false} value for {@code boolean}s or * an exception for other primitives. */ - private Object handleNullValue(String name, Object value, Class paramType) { + private Object handleNullValue(String name, @Nullable Object value, Class paramType) { if (value == null) { if (Boolean.TYPE.equals(paramType)) { return Boolean.FALSE; diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractNamedValueSyncArgumentResolver.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractNamedValueSyncArgumentResolver.java index f0a5e8989e..0fa95b184b 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractNamedValueSyncArgumentResolver.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractNamedValueSyncArgumentResolver.java @@ -23,6 +23,7 @@ import reactor.core.publisher.Mono; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.core.MethodParameter; import org.springframework.core.ReactiveAdapterRegistry; +import org.springframework.lang.Nullable; import org.springframework.web.reactive.BindingContext; import org.springframework.web.reactive.result.method.SyncHandlerMethodArgumentResolver; import org.springframework.web.server.ServerWebExchange; @@ -45,7 +46,7 @@ public abstract class AbstractNamedValueSyncArgumentResolver extends AbstractNam * or {@code null} if default values are not expected to have expressions * @param registry for checking reactive type wrappers */ - protected AbstractNamedValueSyncArgumentResolver(ConfigurableBeanFactory factory, ReactiveAdapterRegistry registry) { + protected AbstractNamedValueSyncArgumentResolver(@Nullable ConfigurableBeanFactory factory, ReactiveAdapterRegistry registry) { super(factory, registry); } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/CookieValueMethodArgumentResolver.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/CookieValueMethodArgumentResolver.java index b5b2d550e0..26f48e16e8 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/CookieValueMethodArgumentResolver.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/CookieValueMethodArgumentResolver.java @@ -22,6 +22,7 @@ import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.core.MethodParameter; import org.springframework.core.ReactiveAdapterRegistry; import org.springframework.http.HttpCookie; +import org.springframework.lang.Nullable; import org.springframework.web.bind.annotation.CookieValue; import org.springframework.web.server.ServerWebExchange; import org.springframework.web.server.ServerWebInputException; @@ -44,7 +45,7 @@ public class CookieValueMethodArgumentResolver extends AbstractNamedValueSyncArg * or {@code null} if default values are not expected to contain expressions * @param registry for checking reactive type wrappers */ - public CookieValueMethodArgumentResolver(ConfigurableBeanFactory factory, ReactiveAdapterRegistry registry) { + public CookieValueMethodArgumentResolver(@Nullable ConfigurableBeanFactory factory, ReactiveAdapterRegistry registry) { super(factory, registry); } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ExpressionValueMethodArgumentResolver.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ExpressionValueMethodArgumentResolver.java index 542b49f964..be602b6120 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ExpressionValueMethodArgumentResolver.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ExpressionValueMethodArgumentResolver.java @@ -22,6 +22,7 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.core.MethodParameter; import org.springframework.core.ReactiveAdapterRegistry; +import org.springframework.lang.Nullable; import org.springframework.web.server.ServerWebExchange; /** @@ -42,7 +43,7 @@ public class ExpressionValueMethodArgumentResolver extends AbstractNamedValueSyn * or {@code null} if default values are not expected to contain expressions * @param registry for checking reactive type wrappers */ - public ExpressionValueMethodArgumentResolver(ConfigurableBeanFactory factory, ReactiveAdapterRegistry registry) { + public ExpressionValueMethodArgumentResolver(@Nullable ConfigurableBeanFactory factory, ReactiveAdapterRegistry registry) { super(factory, registry); } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/PathVariableMethodArgumentResolver.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/PathVariableMethodArgumentResolver.java index 7f749efe5c..8550f00e5c 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/PathVariableMethodArgumentResolver.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/PathVariableMethodArgumentResolver.java @@ -23,6 +23,7 @@ import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.core.MethodParameter; import org.springframework.core.ReactiveAdapterRegistry; import org.springframework.core.convert.converter.Converter; +import org.springframework.lang.Nullable; import org.springframework.ui.Model; import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.PathVariable; @@ -58,7 +59,7 @@ public class PathVariableMethodArgumentResolver extends AbstractNamedValueSyncAr * or {@code null} if default values are not expected to contain expressions * @param registry for checking reactive type wrappers */ - public PathVariableMethodArgumentResolver(ConfigurableBeanFactory factory, ReactiveAdapterRegistry registry) { + public PathVariableMethodArgumentResolver(@Nullable ConfigurableBeanFactory factory, ReactiveAdapterRegistry registry) { super(factory, registry); } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestAttributeMethodArgumentResolver.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestAttributeMethodArgumentResolver.java index 72c3f8a73d..87f95f0c5e 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestAttributeMethodArgumentResolver.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestAttributeMethodArgumentResolver.java @@ -20,6 +20,7 @@ import java.util.Optional; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.core.MethodParameter; import org.springframework.core.ReactiveAdapterRegistry; +import org.springframework.lang.Nullable; import org.springframework.web.bind.annotation.RequestAttribute; import org.springframework.web.bind.annotation.ValueConstants; import org.springframework.web.server.ServerWebExchange; @@ -41,7 +42,7 @@ public class RequestAttributeMethodArgumentResolver extends AbstractNamedValueSy * or {@code null} if default values are not expected to have expressions * @param registry for checking reactive type wrappers */ - public RequestAttributeMethodArgumentResolver(ConfigurableBeanFactory factory, ReactiveAdapterRegistry registry) { + public RequestAttributeMethodArgumentResolver(@Nullable ConfigurableBeanFactory factory, ReactiveAdapterRegistry registry) { super(factory, registry); } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestHeaderMethodArgumentResolver.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestHeaderMethodArgumentResolver.java index 754de6268c..225c6de942 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestHeaderMethodArgumentResolver.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestHeaderMethodArgumentResolver.java @@ -24,6 +24,7 @@ import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.core.MethodParameter; import org.springframework.core.ReactiveAdapterRegistry; import org.springframework.core.convert.ConversionService; +import org.springframework.lang.Nullable; import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.server.ServerWebExchange; import org.springframework.web.server.ServerWebInputException; @@ -52,7 +53,7 @@ public class RequestHeaderMethodArgumentResolver extends AbstractNamedValueSyncA * or {@code null} if default values are not expected to have expressions * @param registry for checking reactive type wrappers */ - public RequestHeaderMethodArgumentResolver(ConfigurableBeanFactory factory, ReactiveAdapterRegistry registry) { + public RequestHeaderMethodArgumentResolver(@Nullable ConfigurableBeanFactory factory, ReactiveAdapterRegistry registry) { super(factory, registry); } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestMappingHandlerAdapter.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestMappingHandlerAdapter.java index a68cd9775a..41037f25bb 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestMappingHandlerAdapter.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestMappingHandlerAdapter.java @@ -29,6 +29,7 @@ import org.springframework.context.ApplicationContextAware; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.core.ReactiveAdapterRegistry; import org.springframework.http.codec.ServerCodecConfigurer; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.bind.support.WebBindingInitializer; import org.springframework.web.method.HandlerMethod; @@ -90,6 +91,7 @@ public class RequestMappingHandlerAdapter implements HandlerAdapter, Application /** * Return the configured WebBindingInitializer, or {@code null} if none. */ + @Nullable public WebBindingInitializer getWebBindingInitializer() { return this.webBindingInitializer; } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestMappingHandlerMapping.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestMappingHandlerMapping.java index 539d54fe75..b3485ec869 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestMappingHandlerMapping.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestMappingHandlerMapping.java @@ -22,6 +22,7 @@ import java.util.Set; import org.springframework.context.EmbeddedValueResolverAware; import org.springframework.core.annotation.AnnotatedElementUtils; +import org.springframework.lang.Nullable; import org.springframework.stereotype.Controller; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; @@ -217,6 +218,7 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi * @return the condition, or {@code null} */ @SuppressWarnings("UnusedParameters") + @Nullable protected RequestCondition getCustomTypeCondition(Class handlerType) { return null; } @@ -235,6 +237,7 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi * @return the condition, or {@code null} */ @SuppressWarnings("UnusedParameters") + @Nullable protected RequestCondition getCustomMethodCondition(Method method) { return null; } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestParamMethodArgumentResolver.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestParamMethodArgumentResolver.java index 41fbba180b..b0f9f6d89b 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestParamMethodArgumentResolver.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestParamMethodArgumentResolver.java @@ -25,6 +25,7 @@ import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.core.MethodParameter; import org.springframework.core.ReactiveAdapterRegistry; import org.springframework.core.convert.converter.Converter; +import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ValueConstants; @@ -68,7 +69,7 @@ public class RequestParamMethodArgumentResolver extends AbstractNamedValueSyncAr * request parameter name is derived from the method parameter name. */ public RequestParamMethodArgumentResolver( - ConfigurableBeanFactory factory, ReactiveAdapterRegistry registry, boolean useDefaultResolution) { + @Nullable ConfigurableBeanFactory factory, ReactiveAdapterRegistry registry, boolean useDefaultResolution) { super(factory, registry); this.useDefaultResolution = useDefaultResolution; diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/package-info.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/package-info.java index eee90dcffd..658110927d 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/package-info.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/package-info.java @@ -1,4 +1,7 @@ /** * Infrastructure for annotation-based handler method processing. */ +@NonNullApi package org.springframework.web.reactive.result.method.annotation; + +import org.springframework.lang.NonNullApi; diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/package-info.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/package-info.java index 9761f929e6..7f281fd83d 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/package-info.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/package-info.java @@ -1,4 +1,7 @@ /** * Infrastructure for handler method processing. */ +@NonNullApi package org.springframework.web.reactive.result.method; + +import org.springframework.lang.NonNullApi; diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/package-info.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/package-info.java index 81324dffa0..ad053e24e1 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/package-info.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/package-info.java @@ -4,4 +4,7 @@ * including the handling of handler result values, e.g. @ResponseBody, view * resolution, and so on. */ +@NonNullApi package org.springframework.web.reactive.result; + +import org.springframework.lang.NonNullApi; diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/AbstractView.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/AbstractView.java index fe55411335..7514eee983 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/AbstractView.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/AbstractView.java @@ -30,6 +30,7 @@ import reactor.core.publisher.Mono; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.http.MediaType; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.server.ServerWebExchange; @@ -121,6 +122,7 @@ public abstract class AbstractView implements View, ApplicationContextAware { /** * Return the name of the RequestContext attribute, if any. */ + @Nullable public String getRequestContextAttribute() { return this.requestContextAttribute; } @@ -249,6 +251,7 @@ public abstract class AbstractView implements View, ApplicationContextAware { * the name {@link #REQUEST_DATA_VALUE_PROCESSOR_BEAN_NAME}. * @return the RequestDataValueProcessor, or null if there is none at the application context. */ + @Nullable protected RequestDataValueProcessor getRequestDataValueProcessor() { ApplicationContext context = getApplicationContext(); if (context != null && context.containsBean(REQUEST_DATA_VALUE_PROCESSOR_BEAN_NAME)) { diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/BindStatus.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/BindStatus.java index 174fd04357..250d1ec8ca 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/BindStatus.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/BindStatus.java @@ -23,6 +23,7 @@ import java.util.List; import org.springframework.beans.BeanWrapper; import org.springframework.beans.PropertyAccessorFactory; import org.springframework.context.NoSuchMessageException; +import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; import org.springframework.validation.BindingResult; import org.springframework.validation.Errors; @@ -186,6 +187,7 @@ public class BindStatus { * Note that the complete bind path as required by the bind tag is * "customer.address.street", if bound to a "customer" bean. */ + @Nullable public String getExpression() { return this.expression; } @@ -196,6 +198,7 @@ public class BindStatus { *

    This value will be an HTML-escaped String if the original value * already was a String. */ + @Nullable public Object getValue() { return this.value; } @@ -205,6 +208,7 @@ public class BindStatus { * '{@code getValue().getClass()}' since '{@code getValue()}' may * return '{@code null}'. */ + @Nullable public Class getValueType() { return this.valueType; } @@ -213,6 +217,7 @@ public class BindStatus { * Return the actual value of the field, i.e. the raw property value, * or {@code null} if not available. */ + @Nullable public Object getActualValue() { return this.actualValue; } @@ -246,6 +251,7 @@ public class BindStatus { * Return the error codes for the field or object, if any. * Returns an empty array instead of null if none. */ + @Nullable public String[] getErrorCodes() { return this.errorCodes; } @@ -304,6 +310,7 @@ public class BindStatus { * @return the current Errors instance, or {@code null} if none * @see org.springframework.validation.BindingResult */ + @Nullable public Errors getErrors() { return this.errors; } @@ -313,6 +320,7 @@ public class BindStatus { * is currently bound to. * @return the current PropertyEditor, or {@code null} if none */ + @Nullable public PropertyEditor getEditor() { return this.editor; } @@ -323,6 +331,7 @@ public class BindStatus { * @param valueClass the value class that an editor is needed for * @return the associated PropertyEditor, or {@code null} if none */ + @Nullable public PropertyEditor findEditor(Class valueClass) { return (this.bindingResult != null ? this.bindingResult.findEditor(this.expression, valueClass) : null); diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/HttpMessageWriterView.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/HttpMessageWriterView.java index 7d3190735f..049cbc597e 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/HttpMessageWriterView.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/HttpMessageWriterView.java @@ -31,6 +31,7 @@ import org.springframework.core.codec.Encoder; import org.springframework.http.MediaType; import org.springframework.http.codec.EncoderHttpMessageWriter; import org.springframework.http.codec.HttpMessageWriter; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.server.ServerWebExchange; @@ -120,6 +121,7 @@ public class HttpMessageWriterView implements View { exchange.getResponse().setComplete(); } + @Nullable private Object getObjectToRender(Map model) { Map result = model.entrySet().stream() diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/Rendering.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/Rendering.java index 590cce525c..0cbcfb43d7 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/Rendering.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/Rendering.java @@ -21,6 +21,7 @@ import java.util.Map; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; +import org.springframework.lang.Nullable; import org.springframework.ui.Model; /** @@ -45,6 +46,7 @@ public interface Rendering { /** * Return the selected {@link String} view name or {@link View} object. */ + @Nullable Object view(); /** @@ -55,6 +57,7 @@ public interface Rendering { /** * Return the HTTP status to set the response to. */ + @Nullable HttpStatus status(); /** diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/RequestContext.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/RequestContext.java index aec51b9022..92acdf3bc0 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/RequestContext.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/RequestContext.java @@ -25,6 +25,7 @@ import org.springframework.context.MessageSource; import org.springframework.context.MessageSourceResolvable; import org.springframework.context.NoSuchMessageException; import org.springframework.http.server.reactive.ServerHttpRequest; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.validation.BindException; import org.springframework.validation.BindingResult; @@ -105,6 +106,7 @@ public class RequestContext { * Return the model Map that this RequestContext encapsulates, if any. * @return the populated model Map, or {@code null} if none available */ + @Nullable public Map getModel() { return this.model; } @@ -169,6 +171,7 @@ public class RequestContext { * Return the {@link RequestDataValueProcessor} instance to apply to in form * tag libraries and to redirect URLs. */ + @Nullable public RequestDataValueProcessor getRequestDataValueProcessor() { return this.dataValueProcessor; } @@ -244,7 +247,7 @@ public class RequestContext { * @param defaultMessage String to return if the lookup fails * @return the message */ - public String getMessage(String code, Object[] args, String defaultMessage) { + public String getMessage(String code, @Nullable Object[] args, String defaultMessage) { return getMessage(code, args, defaultMessage, isDefaultHtmlEscape()); } @@ -255,7 +258,7 @@ public class RequestContext { * @param defaultMessage String to return if the lookup fails * @return the message */ - public String getMessage(String code, List args, String defaultMessage) { + public String getMessage(String code, @Nullable List args, String defaultMessage) { return getMessage(code, (args != null ? args.toArray() : null), defaultMessage, isDefaultHtmlEscape()); } @@ -267,7 +270,7 @@ public class RequestContext { * @param htmlEscape HTML escape the message? * @return the message */ - public String getMessage(String code, Object[] args, String defaultMessage, boolean htmlEscape) { + public String getMessage(String code, @Nullable Object[] args, String defaultMessage, boolean htmlEscape) { String msg = this.messageSource.getMessage(code, args, defaultMessage, this.locale); return (htmlEscape ? HtmlUtils.htmlEscape(msg) : msg); } @@ -289,7 +292,7 @@ public class RequestContext { * @return the message * @throws org.springframework.context.NoSuchMessageException if not found */ - public String getMessage(String code, Object[] args) throws NoSuchMessageException { + public String getMessage(String code, @Nullable Object[] args) throws NoSuchMessageException { return getMessage(code, args, isDefaultHtmlEscape()); } @@ -300,7 +303,7 @@ public class RequestContext { * @return the message * @throws org.springframework.context.NoSuchMessageException if not found */ - public String getMessage(String code, List args) throws NoSuchMessageException { + public String getMessage(String code, @Nullable List args) throws NoSuchMessageException { return getMessage(code, (args != null ? args.toArray() : null), isDefaultHtmlEscape()); } @@ -312,7 +315,7 @@ public class RequestContext { * @return the message * @throws org.springframework.context.NoSuchMessageException if not found */ - public String getMessage(String code, Object[] args, boolean htmlEscape) throws NoSuchMessageException { + public String getMessage(String code, @Nullable Object[] args, boolean htmlEscape) throws NoSuchMessageException { String msg = this.messageSource.getMessage(code, args, this.locale); return (htmlEscape ? HtmlUtils.htmlEscape(msg) : msg); } @@ -345,6 +348,7 @@ public class RequestContext { * @param name name of the bind object * @return the Errors instance, or {@code null} if not found */ + @Nullable public Errors getErrors(String name) { return getErrors(name, isDefaultHtmlEscape()); } @@ -355,6 +359,7 @@ public class RequestContext { * @param htmlEscape create an Errors instance with automatic HTML escaping? * @return the Errors instance, or {@code null} if not found */ + @Nullable public Errors getErrors(String name, boolean htmlEscape) { if (this.errorsMap == null) { this.errorsMap = new HashMap<>(); @@ -386,6 +391,7 @@ public class RequestContext { * @return the model object */ @SuppressWarnings("unchecked") + @Nullable protected T getModelObject(String modelName) { T modelObject = (T) this.model.get(modelName); if (modelObject == null) { diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/RequestDataValueProcessor.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/RequestDataValueProcessor.java index 400db5047d..10aa134088 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/RequestDataValueProcessor.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/RequestDataValueProcessor.java @@ -17,6 +17,7 @@ package org.springframework.web.reactive.result.view; import java.util.Map; +import org.springframework.lang.Nullable; import org.springframework.web.server.ServerWebExchange; /** @@ -61,6 +62,7 @@ public interface RequestDataValueProcessor { * @param exchange the current exchange * @return additional hidden form fields to be added, or {@code null} */ + @Nullable Map getExtraHiddenFields(ServerWebExchange exchange); /** diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/UrlBasedViewResolver.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/UrlBasedViewResolver.java index 0dc0236bbe..630b63ea05 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/UrlBasedViewResolver.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/UrlBasedViewResolver.java @@ -23,6 +23,7 @@ import reactor.core.publisher.Mono; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.InitializingBean; +import org.springframework.lang.Nullable; import org.springframework.util.PatternMatchUtils; /** @@ -176,6 +177,7 @@ public class UrlBasedViewResolver extends ViewResolverSupport implements ViewRes /** * Return the name of the RequestContext attribute for all views, if any. */ + @Nullable protected String getRequestContextAttribute() { return this.requestContextAttribute; } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/View.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/View.java index 61089fe752..268b7dc10b 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/View.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/View.java @@ -22,6 +22,7 @@ import java.util.Map; import reactor.core.publisher.Mono; import org.springframework.http.MediaType; +import org.springframework.lang.Nullable; import org.springframework.web.reactive.HandlerResult; import org.springframework.web.server.ServerWebExchange; @@ -64,6 +65,6 @@ public interface View { * @param exchange the current exchange * @return {@code Mono} to represent when and if rendering succeeds */ - Mono render(Map model, MediaType contentType, ServerWebExchange exchange); + Mono render(@Nullable Map model, MediaType contentType, ServerWebExchange exchange); } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/freemarker/package-info.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/freemarker/package-info.java index 2514b6b9b8..b932889b6f 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/freemarker/package-info.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/freemarker/package-info.java @@ -4,4 +4,7 @@ * as Spring web view technology. * Contains a View implementation for FreeMarker templates. */ +@NonNullApi package org.springframework.web.reactive.result.view.freemarker; + +import org.springframework.lang.NonNullApi; diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/package-info.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/package-info.java index c789bb2632..238f9cbbb0 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/package-info.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/package-info.java @@ -1,4 +1,7 @@ /** * Support for result handling through view resolution. */ +@NonNullApi package org.springframework.web.reactive.result.view; + +import org.springframework.lang.NonNullApi; diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/script/ScriptTemplateView.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/script/ScriptTemplateView.java index 0046be875a..84da1de16a 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/script/ScriptTemplateView.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/script/ScriptTemplateView.java @@ -39,6 +39,7 @@ import org.springframework.core.io.ResourceLoader; import org.springframework.core.io.buffer.DataBuffer; import org.springframework.http.MediaType; import org.springframework.http.server.reactive.ServerHttpResponse; +import org.springframework.lang.Nullable; import org.springframework.scripting.support.StandardScriptEvalException; import org.springframework.scripting.support.StandardScriptUtils; import org.springframework.util.Assert; @@ -258,6 +259,7 @@ public class ScriptTemplateView extends AbstractUrlBasedView { } } + @Nullable protected Resource getResource(String location) { for (String path : this.resourceLoaderPaths) { Resource resource = this.resourceLoader.getResource(path + location); diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/script/package-info.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/script/package-info.java index 5ad2ee25a4..6f155192ae 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/script/package-info.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/script/package-info.java @@ -3,4 +3,7 @@ * (as included in Java 6+), e.g. using JavaScript via Nashorn on JDK 8. * Contains a View implementation for scripted templates. */ +@NonNullApi package org.springframework.web.reactive.result.view.script; + +import org.springframework.lang.NonNullApi; diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/CloseStatus.java b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/CloseStatus.java index fb9dfd4295..e39d10fa9a 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/CloseStatus.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/CloseStatus.java @@ -16,6 +16,7 @@ package org.springframework.web.reactive.socket; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; @@ -167,6 +168,7 @@ public final class CloseStatus { /** * Return the reason, or {@code null} if none. */ + @Nullable public String getReason() { return this.reason; } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/HandshakeInfo.java b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/HandshakeInfo.java index 85b06093b8..48bd2a8e5d 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/HandshakeInfo.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/HandshakeInfo.java @@ -22,6 +22,7 @@ import java.security.Principal; import reactor.core.publisher.Mono; import org.springframework.http.HttpHeaders; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -88,6 +89,7 @@ public class HandshakeInfo { * @see * https://tools.ietf.org/html/rfc6455#section-1.9 */ + @Nullable public String getSubProtocol() { return this.protocol; } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/adapter/package-info.java b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/adapter/package-info.java index aa675f1b3b..47a1bd6aa2 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/adapter/package-info.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/adapter/package-info.java @@ -1,4 +1,7 @@ /** * Classes adapting Spring's Reactive WebSocket API to and from WebSocket runtimes. */ +@NonNullApi package org.springframework.web.reactive.socket.adapter; + +import org.springframework.lang.NonNullApi; diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/client/package-info.java b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/client/package-info.java index 81087aab33..4ad4dbea74 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/client/package-info.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/client/package-info.java @@ -1,4 +1,7 @@ /** * Client support for WebSocket interactions. */ +@NonNullApi package org.springframework.web.reactive.socket.client; + +import org.springframework.lang.NonNullApi; diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/package-info.java b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/package-info.java index 4d611c0ff9..38e53ece1e 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/package-info.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/package-info.java @@ -1,4 +1,7 @@ /** * Abstractions and support classes for reactive WebSocket interactions. */ +@NonNullApi package org.springframework.web.reactive.socket; + +import org.springframework.lang.NonNullApi; diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/RequestUpgradeStrategy.java b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/RequestUpgradeStrategy.java index 35654ce806..16f57c3eff 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/RequestUpgradeStrategy.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/RequestUpgradeStrategy.java @@ -20,6 +20,7 @@ import reactor.core.publisher.Mono; import org.springframework.http.server.reactive.ServerHttpRequest; import org.springframework.http.server.reactive.ServerHttpResponse; +import org.springframework.lang.Nullable; import org.springframework.web.reactive.socket.WebSocketHandler; import org.springframework.web.server.ServerWebExchange; @@ -45,6 +46,6 @@ public interface RequestUpgradeStrategy { * @return completion {@code Mono} to indicate the outcome of the * WebSocket session handling. */ - Mono upgrade(ServerWebExchange exchange, WebSocketHandler webSocketHandler, String subProtocol); + Mono upgrade(ServerWebExchange exchange, WebSocketHandler webSocketHandler, @Nullable String subProtocol); } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/package-info.java b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/package-info.java index 0c0cb9c23c..7c53cdd73b 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/package-info.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/package-info.java @@ -1,4 +1,7 @@ /** * Server support for WebSocket interactions. */ +@NonNullApi package org.springframework.web.reactive.socket.server; + +import org.springframework.lang.NonNullApi; diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/support/HandshakeWebSocketService.java b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/support/HandshakeWebSocketService.java index a7ab423019..bf39512f10 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/support/HandshakeWebSocketService.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/support/HandshakeWebSocketService.java @@ -27,6 +27,7 @@ import org.springframework.context.Lifecycle; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.server.reactive.ServerHttpRequest; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.ReflectionUtils; @@ -208,6 +209,7 @@ public class HandshakeWebSocketService implements WebSocketService, Lifecycle { return Mono.error(new ServerWebInputException(reason)); } + @Nullable private String selectProtocol(HttpHeaders headers, WebSocketHandler handler) { String protocolHeader = headers.getFirst(SEC_WEBSOCKET_PROTOCOL); if (protocolHeader != null) { diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/support/package-info.java b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/support/package-info.java index 4f4a56ea33..17e4ed81f1 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/support/package-info.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/support/package-info.java @@ -1,4 +1,7 @@ /** * Server-side support classes for WebSocket requests. */ +@NonNullApi package org.springframework.web.reactive.socket.server.support; + +import org.springframework.lang.NonNullApi; diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/upgrade/package-info.java b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/upgrade/package-info.java index 6fdce1fc11..0b1cc54e8a 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/upgrade/package-info.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/upgrade/package-info.java @@ -2,4 +2,7 @@ * Holds implementations of * {@link org.springframework.web.reactive.socket.server.RequestUpgradeStrategy}. */ +@NonNullApi package org.springframework.web.reactive.socket.server.upgrade; + +import org.springframework.lang.NonNullApi; diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/support/package-info.java b/spring-webflux/src/main/java/org/springframework/web/reactive/support/package-info.java index 09bf03bcf5..d979bd71a1 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/support/package-info.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/support/package-info.java @@ -1,4 +1,7 @@ /** * Support classes for Spring WebFlux setup. */ -package org.springframework.web.reactive.support; \ No newline at end of file +@NonNullApi +package org.springframework.web.reactive.support; + +import org.springframework.lang.NonNullApi; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/DispatcherServlet.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/DispatcherServlet.java index a7b7a0ed6b..e5460a7e77 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/DispatcherServlet.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/DispatcherServlet.java @@ -28,6 +28,7 @@ import java.util.Locale; import java.util.Map; import java.util.Properties; import java.util.Set; + import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; @@ -46,6 +47,7 @@ import org.springframework.core.annotation.AnnotationAwareOrderComparator; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.support.PropertiesLoaderUtils; import org.springframework.http.server.ServletServerHttpRequest; +import org.springframework.lang.Nullable; import org.springframework.ui.context.ThemeSource; import org.springframework.util.ClassUtils; import org.springframework.util.StringUtils; @@ -767,6 +769,7 @@ public class DispatcherServlet extends FrameworkServlet { * @return the ThemeSource, if any * @see #getWebApplicationContext() */ + @Nullable public final ThemeSource getThemeSource() { if (getWebApplicationContext() instanceof ThemeSource) { return (ThemeSource) getWebApplicationContext(); @@ -781,6 +784,7 @@ public class DispatcherServlet extends FrameworkServlet { * @return the MultipartResolver used by this servlet, or {@code null} if none * (indicating that no multipart support is available) */ + @Nullable public final MultipartResolver getMultipartResolver() { return this.multipartResolver; } @@ -1151,6 +1155,7 @@ public class DispatcherServlet extends FrameworkServlet { * @param request current HTTP request * @return the HandlerExecutionChain, or {@code null} if no handler could be found */ + @Nullable protected HandlerExecutionChain getHandler(HttpServletRequest request) throws Exception { for (HandlerMapping hm : this.handlerMappings) { if (logger.isTraceEnabled()) { @@ -1213,8 +1218,9 @@ public class DispatcherServlet extends FrameworkServlet { * @return a corresponding ModelAndView to forward to * @throws Exception if no error ModelAndView found */ + @Nullable protected ModelAndView processHandlerException(HttpServletRequest request, HttpServletResponse response, - Object handler, Exception ex) throws Exception { + @Nullable Object handler, Exception ex) throws Exception { // Check registered HandlerExceptionResolvers... ModelAndView exMv = null; @@ -1300,6 +1306,7 @@ public class DispatcherServlet extends FrameworkServlet { * @return the view name (or {@code null} if no default found) * @throws Exception if view name translation failed */ + @Nullable protected String getDefaultViewName(HttpServletRequest request) throws Exception { return this.viewNameTranslator.getViewName(request); } @@ -1318,6 +1325,7 @@ public class DispatcherServlet extends FrameworkServlet { * (typically in case of problems creating an actual View object) * @see ViewResolver#resolveViewName */ + @Nullable protected View resolveViewName(String viewName, Map model, Locale locale, HttpServletRequest request) throws Exception { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/FlashMap.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/FlashMap.java index df35f702d6..a40fb7cbfe 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/FlashMap.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/FlashMap.java @@ -18,6 +18,7 @@ package org.springframework.web.servlet; import java.util.HashMap; +import org.springframework.lang.Nullable; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.util.ObjectUtils; @@ -67,6 +68,7 @@ public final class FlashMap extends HashMap implements Comparabl /** * Return the target URL path (or {@code null} if none specified). */ + @Nullable public String getTargetRequestPath() { return this.targetRequestPath; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/FlashMapManager.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/FlashMapManager.java index 527009e58e..5b42032699 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/FlashMapManager.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/FlashMapManager.java @@ -19,6 +19,8 @@ package org.springframework.web.servlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.springframework.lang.Nullable; + /** * A strategy interface for retrieving and saving FlashMap instances. * See {@link FlashMap} for a general overview of flash attributes. @@ -40,6 +42,7 @@ public interface FlashMapManager { * @param response the current response * @return a FlashMap matching the current request or {@code null} */ + @Nullable FlashMap retrieveAndUpdate(HttpServletRequest request, HttpServletResponse response); /** diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/FrameworkServlet.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/FrameworkServlet.java index 7cb980d456..14e5393ff1 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/FrameworkServlet.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/FrameworkServlet.java @@ -21,6 +21,7 @@ import java.security.Principal; import java.util.ArrayList; import java.util.List; import java.util.concurrent.Callable; + import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; @@ -43,6 +44,7 @@ import org.springframework.core.GenericTypeResolver; import org.springframework.core.annotation.AnnotationAwareOrderComparator; import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.http.HttpMethod; +import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; @@ -321,6 +323,7 @@ public abstract class FrameworkServlet extends HttpServletBean implements Applic /** * Return the custom WebApplicationContext id, if any. */ + @Nullable public String getContextId() { return this.contextId; } @@ -353,6 +356,7 @@ public abstract class FrameworkServlet extends HttpServletBean implements Applic /** * Return the explicit context config location, if any. */ + @Nullable public String getContextConfigLocation() { return this.contextConfigLocation; } @@ -578,6 +582,7 @@ public abstract class FrameworkServlet extends HttpServletBean implements Applic * @return the WebApplicationContext for this servlet, or {@code null} if not found * @see #getContextAttribute() */ + @Nullable protected WebApplicationContext findWebApplicationContext() { String attrName = getContextAttribute(); if (attrName == null) { @@ -606,7 +611,7 @@ public abstract class FrameworkServlet extends HttpServletBean implements Applic * @return the WebApplicationContext for this servlet * @see org.springframework.web.context.support.XmlWebApplicationContext */ - protected WebApplicationContext createWebApplicationContext(ApplicationContext parent) { + protected WebApplicationContext createWebApplicationContext(@Nullable ApplicationContext parent) { Class contextClass = getContextClass(); if (this.logger.isDebugEnabled()) { this.logger.debug("Servlet with name '" + getServletName() + @@ -673,7 +678,7 @@ public abstract class FrameworkServlet extends HttpServletBean implements Applic * @see org.springframework.web.context.support.XmlWebApplicationContext * @see #createWebApplicationContext(ApplicationContext) */ - protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) { + protected WebApplicationContext createWebApplicationContext(@Nullable WebApplicationContext parent) { return createWebApplicationContext((ApplicationContext) parent); } @@ -1007,6 +1012,7 @@ public abstract class FrameworkServlet extends HttpServletBean implements Applic * @return the corresponding LocaleContext, or {@code null} if none to bind * @see LocaleContextHolder#setLocaleContext */ + @Nullable protected LocaleContext buildLocaleContext(HttpServletRequest request) { return new SimpleLocaleContext(request.getLocale()); } @@ -1022,6 +1028,7 @@ public abstract class FrameworkServlet extends HttpServletBean implements Applic * the previously bound instance (or not binding any, if none bound before) * @see RequestContextHolder#setRequestAttributes */ + @Nullable protected ServletRequestAttributes buildRequestAttributes( HttpServletRequest request, HttpServletResponse response, RequestAttributes previousAttributes) { @@ -1080,6 +1087,7 @@ public abstract class FrameworkServlet extends HttpServletBean implements Applic * @return the username, or {@code null} if none found * @see javax.servlet.http.HttpServletRequest#getUserPrincipal() */ + @Nullable protected String getUsernameForRequest(HttpServletRequest request) { Principal userPrincipal = request.getUserPrincipal(); return (userPrincipal != null ? userPrincipal.getName() : null); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/HandlerAdapter.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/HandlerAdapter.java index f456d25ebb..0957eca869 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/HandlerAdapter.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/HandlerAdapter.java @@ -19,6 +19,8 @@ package org.springframework.web.servlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.springframework.lang.Nullable; + /** * MVC framework SPI, allowing parameterization of the core MVC workflow. * @@ -72,6 +74,7 @@ public interface HandlerAdapter { * @return ModelAndView object with the name of the view and the required * model data, or {@code null} if the request has been handled directly */ + @Nullable ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception; /** diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/HandlerExceptionResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/HandlerExceptionResolver.java index d7d1b6d9b5..f870fe5a20 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/HandlerExceptionResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/HandlerExceptionResolver.java @@ -19,6 +19,8 @@ package org.springframework.web.servlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.springframework.lang.Nullable; + /** * Interface to be implemented by objects that can resolve exceptions thrown during * handler mapping or execution, in the typical case to error views. Implementors are @@ -47,7 +49,8 @@ public interface HandlerExceptionResolver { * @return a corresponding {@code ModelAndView} to forward to, or {@code null} * for default processing */ + @Nullable ModelAndView resolveException( - HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex); + HttpServletRequest request, HttpServletResponse response, @Nullable Object handler, Exception ex); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/HandlerExecutionChain.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/HandlerExecutionChain.java index 4b7d82ad6e..45a6f740a2 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/HandlerExecutionChain.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/HandlerExecutionChain.java @@ -18,12 +18,14 @@ package org.springframework.web.servlet; import java.util.ArrayList; import java.util.List; + import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; import org.springframework.util.ObjectUtils; @@ -81,6 +83,7 @@ public class HandlerExecutionChain { * Return the handler object to execute. * @return the handler object (may be {@code null}) */ + @Nullable public Object getHandler() { return this.handler; } @@ -111,6 +114,7 @@ public class HandlerExecutionChain { * Return the array of interceptors to apply (in the given order). * @return the array of HandlerInterceptors instances (may be {@code null}) */ + @Nullable public HandlerInterceptor[] getInterceptors() { if (this.interceptors == null && this.interceptorList != null) { this.interceptors = this.interceptorList.toArray(new HandlerInterceptor[this.interceptorList.size()]); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/HandlerInterceptor.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/HandlerInterceptor.java index 2fffa1c3ec..4953f4553c 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/HandlerInterceptor.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/HandlerInterceptor.java @@ -19,6 +19,7 @@ package org.springframework.web.servlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.springframework.lang.Nullable; import org.springframework.web.method.HandlerMethod; /** @@ -120,7 +121,7 @@ public interface HandlerInterceptor { * @throws Exception in case of errors */ default void postHandle( - HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) + HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable ModelAndView modelAndView) throws Exception { } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/HandlerMapping.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/HandlerMapping.java index 00d26677e9..02ad6e7b74 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/HandlerMapping.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/HandlerMapping.java @@ -18,6 +18,8 @@ package org.springframework.web.servlet; import javax.servlet.http.HttpServletRequest; +import org.springframework.lang.Nullable; + /** * Interface to be implemented by objects that define a mapping between * requests and handler objects. @@ -126,6 +128,7 @@ public interface HandlerMapping { * any interceptors, or {@code null} if no mapping found * @throws Exception if there is an internal error */ + @Nullable HandlerExecutionChain getHandler(HttpServletRequest request) throws Exception; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/HttpServletBean.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/HttpServletBean.java index 46e6461c78..d10f4ebb4c 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/HttpServletBean.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/HttpServletBean.java @@ -19,6 +19,7 @@ package org.springframework.web.servlet; import java.util.Enumeration; import java.util.HashSet; import java.util.Set; + import javax.servlet.ServletConfig; import javax.servlet.ServletContext; import javax.servlet.ServletException; @@ -40,6 +41,7 @@ import org.springframework.core.env.EnvironmentCapable; import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceEditor; import org.springframework.core.io.ResourceLoader; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; @@ -202,6 +204,7 @@ public abstract class HttpServletBean extends HttpServlet implements Environment * @see #getServletConfig() */ @Override + @Nullable public final String getServletName() { return (getServletConfig() != null ? getServletConfig().getServletName() : null); } @@ -212,6 +215,7 @@ public abstract class HttpServletBean extends HttpServlet implements Environment * @see #getServletConfig() */ @Override + @Nullable public final ServletContext getServletContext() { return (getServletConfig() != null ? getServletConfig().getServletContext() : null); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/LocaleContextResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/LocaleContextResolver.java index ffa7b24f7f..ed86f27bd3 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/LocaleContextResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/LocaleContextResolver.java @@ -17,10 +17,12 @@ package org.springframework.web.servlet; import java.util.Locale; + import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.context.i18n.LocaleContext; +import org.springframework.lang.Nullable; /** * Extension of {@link LocaleResolver}, adding support for a rich locale context @@ -68,6 +70,6 @@ public interface LocaleContextResolver extends LocaleResolver { * @see org.springframework.context.i18n.SimpleLocaleContext * @see org.springframework.context.i18n.SimpleTimeZoneAwareLocaleContext */ - void setLocaleContext(HttpServletRequest request, HttpServletResponse response, LocaleContext localeContext); + void setLocaleContext(HttpServletRequest request, HttpServletResponse response, @Nullable LocaleContext localeContext); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/LocaleResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/LocaleResolver.java index 2d0f954022..b7710b40f3 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/LocaleResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/LocaleResolver.java @@ -17,9 +17,12 @@ package org.springframework.web.servlet; import java.util.Locale; + import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.springframework.lang.Nullable; + /** * Interface for web-based locale resolution strategies that allows for * both locale resolution via the request and locale modification via @@ -66,6 +69,6 @@ public interface LocaleResolver { * @throws UnsupportedOperationException if the LocaleResolver * implementation does not support dynamic changing of the locale */ - void setLocale(HttpServletRequest request, HttpServletResponse response, Locale locale); + void setLocale(HttpServletRequest request, HttpServletResponse response, @Nullable Locale locale); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/ModelAndView.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/ModelAndView.java index 237526d0c4..923a0391e9 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/ModelAndView.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/ModelAndView.java @@ -19,6 +19,7 @@ package org.springframework.web.servlet; import java.util.Map; import org.springframework.http.HttpStatus; +import org.springframework.lang.Nullable; import org.springframework.ui.ModelMap; import org.springframework.util.CollectionUtils; @@ -96,7 +97,7 @@ public class ModelAndView { * (Objects). Model entries may not be {@code null}, but the * model Map may be {@code null} if there is no model data. */ - public ModelAndView(String viewName, Map model) { + public ModelAndView(String viewName, @Nullable Map model) { this.view = viewName; if (model != null) { getModelMap().addAllAttributes(model); @@ -113,7 +114,7 @@ public class ModelAndView { * (Objects). Model entries may not be {@code null}, but the * model Map may be {@code null} if there is no model data. */ - public ModelAndView(View view, Map model) { + public ModelAndView(View view, @Nullable Map model) { this.view = view; if (model != null) { getModelMap().addAllAttributes(model); @@ -144,7 +145,7 @@ public class ModelAndView { * (to be set just prior to View rendering) * @since 4.3 */ - public ModelAndView(String viewName, Map model, HttpStatus status) { + public ModelAndView(String viewName, @Nullable Map model, HttpStatus status) { this.view = viewName; if (model != null) { getModelMap().addAllAttributes(model); @@ -189,6 +190,7 @@ public class ModelAndView { * Return the view name to be resolved by the DispatcherServlet * via a ViewResolver, or {@code null} if we are using a View object. */ + @Nullable public String getViewName() { return (this.view instanceof String ? (String) this.view : null); } @@ -205,6 +207,7 @@ public class ModelAndView { * Return the View object, or {@code null} if we are using a view name * to be resolved by the DispatcherServlet via a ViewResolver. */ + @Nullable public View getView() { return (this.view instanceof View ? (View) this.view : null); } @@ -230,6 +233,7 @@ public class ModelAndView { * Return the model map. May return {@code null}. * Called by DispatcherServlet for evaluation of the model. */ + @Nullable protected Map getModelInternal() { return this.model; } @@ -265,6 +269,7 @@ public class ModelAndView { * Return the configured HTTP status for the response, if any. * @since 4.3 */ + @Nullable public HttpStatus getStatus() { return this.status; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/RequestToViewNameTranslator.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/RequestToViewNameTranslator.java index 7c47cd3aa8..8eeffd5e47 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/RequestToViewNameTranslator.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/RequestToViewNameTranslator.java @@ -18,6 +18,8 @@ package org.springframework.web.servlet; import javax.servlet.http.HttpServletRequest; +import org.springframework.lang.Nullable; + /** * Strategy interface for translating an incoming * {@link javax.servlet.http.HttpServletRequest} into a @@ -36,6 +38,7 @@ public interface RequestToViewNameTranslator { * @return the view name (or {@code null} if no default found) * @throws Exception if view name translation fails */ + @Nullable String getViewName(HttpServletRequest request) throws Exception; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/ResourceServlet.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/ResourceServlet.java index e927935005..2f55dab080 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/ResourceServlet.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/ResourceServlet.java @@ -23,6 +23,7 @@ import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.springframework.lang.Nullable; import org.springframework.util.AntPathMatcher; import org.springframework.util.PathMatcher; import org.springframework.util.StringUtils; @@ -235,6 +236,7 @@ public class ResourceServlet extends HttpServletBean { * @return the URL of the target resource, or {@code null} if none found * @see #RESOURCE_PARAM_NAME */ + @Nullable protected String determineResourceUrl(HttpServletRequest request) { return request.getParameter(RESOURCE_PARAM_NAME); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/View.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/View.java index f63658d0bf..aa452b24b1 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/View.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/View.java @@ -17,10 +17,12 @@ package org.springframework.web.servlet; import java.util.Map; + import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.http.MediaType; +import org.springframework.lang.Nullable; /** * MVC View for a web interaction. Implementations are responsible for rendering @@ -73,6 +75,7 @@ public interface View { * @return the content type String (optionally including a character set), * or {@code null} if not predetermined. */ + @Nullable String getContentType(); /** @@ -87,6 +90,6 @@ public interface View { * @param response HTTP response we are building * @throws Exception if rendering failed */ - void render(Map model, HttpServletRequest request, HttpServletResponse response) throws Exception; + void render(@Nullable Map model, HttpServletRequest request, HttpServletResponse response) throws Exception; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/ViewResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/ViewResolver.java index e6a50cc2df..3f0942230a 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/ViewResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/ViewResolver.java @@ -18,6 +18,8 @@ package org.springframework.web.servlet; import java.util.Locale; +import org.springframework.lang.Nullable; + /** * Interface to be implemented by objects that can resolve views by name. * @@ -50,6 +52,7 @@ public interface ViewResolver { * @throws Exception if the view cannot be resolved * (typically in case of problems creating an actual View object) */ + @Nullable View resolveViewName(String viewName, Locale locale) throws Exception; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/AnnotationDrivenBeanDefinitionParser.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/AnnotationDrivenBeanDefinitionParser.java index 410eb31416..ba21278d3c 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/AnnotationDrivenBeanDefinitionParser.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/AnnotationDrivenBeanDefinitionParser.java @@ -56,6 +56,7 @@ import org.springframework.http.converter.support.AllEncompassingFormHttpMessage import org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter; import org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter; import org.springframework.http.converter.xml.SourceHttpMessageConverter; +import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.util.StringUtils; import org.springframework.util.xml.DomUtils; @@ -355,6 +356,7 @@ class AnnotationDrivenBeanDefinitionParser implements BeanDefinitionParser { return conversionServiceRef; } + @Nullable private RuntimeBeanReference getValidator(Element element, Object source, ParserContext parserContext) { if (element.hasAttribute("validator")) { return new RuntimeBeanReference(element.getAttribute("validator")); @@ -450,6 +452,7 @@ class AnnotationDrivenBeanDefinitionParser implements BeanDefinitionParser { return props; } + @Nullable private RuntimeBeanReference getMessageCodesResolver(Element element) { if (element.hasAttribute("message-codes-resolver")) { return new RuntimeBeanReference(element.getAttribute("message-codes-resolver")); @@ -464,6 +467,7 @@ class AnnotationDrivenBeanDefinitionParser implements BeanDefinitionParser { return (asyncElement != null) ? asyncElement.getAttribute("default-timeout") : null; } + @Nullable private RuntimeBeanReference getAsyncExecutor(Element element) { Element asyncElement = DomUtils.getChildElementByTagName(element, "async-support"); if (asyncElement != null) { @@ -508,6 +512,7 @@ class AnnotationDrivenBeanDefinitionParser implements BeanDefinitionParser { return interceptors; } + @Nullable private ManagedList getArgumentResolvers(Element element, ParserContext parserContext) { Element resolversElement = DomUtils.getChildElementByTagName(element, "argument-resolvers"); if (resolversElement != null) { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/MvcNamespaceUtils.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/MvcNamespaceUtils.java index fb787d1a0a..affde15c09 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/MvcNamespaceUtils.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/MvcNamespaceUtils.java @@ -24,6 +24,7 @@ import org.springframework.beans.factory.config.RuntimeBeanReference; import org.springframework.beans.factory.parsing.BeanComponentDefinition; import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.beans.factory.xml.ParserContext; +import org.springframework.lang.Nullable; import org.springframework.util.AntPathMatcher; import org.springframework.util.PathMatcher; import org.springframework.web.cors.CorsConfiguration; @@ -183,6 +184,7 @@ abstract class MvcNamespaceUtils { * with the {@code annotation-driven} element. * @return a bean definition, bean reference, or null. */ + @Nullable public static Object getContentNegotiationManager(ParserContext context) { String name = AnnotationDrivenBeanDefinitionParser.HANDLER_MAPPING_BEAN_NAME; if (context.getRegistry().containsBeanDefinition(name)) { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/DefaultServletHandlerConfigurer.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/DefaultServletHandlerConfigurer.java index c1e617836e..d5b1a9eb65 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/DefaultServletHandlerConfigurer.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/DefaultServletHandlerConfigurer.java @@ -18,8 +18,10 @@ package org.springframework.web.servlet.config.annotation; import java.util.HashMap; import java.util.Map; + import javax.servlet.ServletContext; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.HttpRequestHandler; import org.springframework.web.servlet.DispatcherServlet; @@ -80,6 +82,7 @@ public class DefaultServletHandlerConfigurer { * {@link DefaultServletHttpRequestHandler} instance mapped to {@code "/**"}; or {@code null} if * default servlet handling was not been enabled. */ + @Nullable protected AbstractHandlerMapping getHandlerMapping() { if (handler == null) { return null; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ResourceHandlerRegistry.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ResourceHandlerRegistry.java index 7cd4e2a32f..f26aba3018 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ResourceHandlerRegistry.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ResourceHandlerRegistry.java @@ -21,10 +21,12 @@ import java.util.Arrays; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; + import javax.servlet.ServletContext; import org.springframework.beans.factory.BeanInitializationException; import org.springframework.context.ApplicationContext; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.HttpRequestHandler; import org.springframework.web.accept.ContentNegotiationManager; @@ -131,6 +133,7 @@ public class ResourceHandlerRegistry { * Return a handler mapping with the mapped resource handlers; or {@code null} in case * of no registrations. */ + @Nullable protected AbstractHandlerMapping getHandlerMapping() { if (this.registrations.isEmpty()) { return null; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ViewControllerRegistry.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ViewControllerRegistry.java index 2756733d4b..0a28f73505 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ViewControllerRegistry.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ViewControllerRegistry.java @@ -23,6 +23,7 @@ import java.util.Map; import org.springframework.context.ApplicationContext; import org.springframework.http.HttpStatus; +import org.springframework.lang.Nullable; import org.springframework.web.servlet.handler.AbstractHandlerMapping; import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping; @@ -105,6 +106,7 @@ public class ViewControllerRegistry { * Return the {@code HandlerMapping} that contains the registered view * controller mappings, or {@code null} for no registrations. */ + @Nullable protected AbstractHandlerMapping getHandlerMapping() { if (this.registrations.isEmpty() && this.redirectRegistrations.isEmpty()) { return null; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.java index 73660ce5b8..3ff089689b 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.java @@ -22,6 +22,7 @@ import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Map; + import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; @@ -56,6 +57,7 @@ import org.springframework.http.converter.support.AllEncompassingFormHttpMessage import org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter; import org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter; import org.springframework.http.converter.xml.SourceHttpMessageConverter; +import org.springframework.lang.Nullable; import org.springframework.util.AntPathMatcher; import org.springframework.util.ClassUtils; import org.springframework.util.PathMatcher; @@ -584,6 +586,7 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv /** * Override this method to provide a custom {@link MessageCodesResolver}. */ + @Nullable protected MessageCodesResolver getMessageCodesResolver() { return null; } @@ -646,6 +649,7 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv /** * Override this method to provide a custom {@link Validator}. */ + @Nullable protected Validator getValidator() { return null; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurer.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurer.java index e576c7bb59..750aeff6ff 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurer.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurer.java @@ -22,6 +22,7 @@ import org.springframework.core.convert.converter.Converter; import org.springframework.format.Formatter; import org.springframework.format.FormatterRegistry; import org.springframework.http.converter.HttpMessageConverter; +import org.springframework.lang.Nullable; import org.springframework.validation.MessageCodesResolver; import org.springframework.validation.Validator; import org.springframework.web.method.support.HandlerMethodArgumentResolver; @@ -214,6 +215,7 @@ public interface WebMvcConfigurer { * {@link org.springframework.validation.beanvalidation.OptionalValidatorFactoryBean}. * Leave the return value as {@code null} to keep the default. */ + @Nullable default Validator getValidator() { return null; } @@ -223,6 +225,7 @@ public interface WebMvcConfigurer { * from data binding and validation error codes. Leave the return value as * {@code null} to keep the default. */ + @Nullable default MessageCodesResolver getMessageCodesResolver() { return null; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/package-info.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/package-info.java index 0ed876c41c..9c99c47383 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/package-info.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/package-info.java @@ -1,4 +1,7 @@ /** * Annotation-based setup for Spring MVC. */ +@NonNullApi package org.springframework.web.servlet.config.annotation; + +import org.springframework.lang.NonNullApi; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/package-info.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/package-info.java index 5fbb39dd06..29c110b010 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/package-info.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/package-info.java @@ -1,4 +1,7 @@ /** * Defines the XML configuration namespace for Spring MVC. */ +@NonNullApi package org.springframework.web.servlet.config; + +import org.springframework.lang.NonNullApi; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractDetectingUrlHandlerMapping.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractDetectingUrlHandlerMapping.java index c06bb4eeff..100f7e114c 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractDetectingUrlHandlerMapping.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractDetectingUrlHandlerMapping.java @@ -19,6 +19,7 @@ package org.springframework.web.servlet.handler; import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanFactoryUtils; import org.springframework.context.ApplicationContextException; +import org.springframework.lang.Nullable; import org.springframework.util.ObjectUtils; /** @@ -96,6 +97,7 @@ public abstract class AbstractDetectingUrlHandlerMapping extends AbstractUrlHand * @return the URLs determined for the bean, * or {@code null} or an empty array if none */ + @Nullable protected abstract String[] determineUrlsForHandler(String beanName); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerExceptionResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerExceptionResolver.java index 50997f55bd..3fe557beeb 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerExceptionResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerExceptionResolver.java @@ -25,6 +25,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.core.Ordered; +import org.springframework.lang.Nullable; import org.springframework.web.servlet.HandlerExceptionResolver; import org.springframework.web.servlet.ModelAndView; @@ -157,7 +158,7 @@ public abstract class AbstractHandlerExceptionResolver implements HandlerExcepti * @see #setMappedHandlers * @see #setMappedHandlerClasses */ - protected boolean shouldApplyTo(HttpServletRequest request, Object handler) { + protected boolean shouldApplyTo(HttpServletRequest request, @Nullable Object handler) { if (handler != null) { if (this.mappedHandlers != null && this.mappedHandlers.contains(handler)) { return true; @@ -239,7 +240,8 @@ public abstract class AbstractHandlerExceptionResolver implements HandlerExcepti * @param ex the exception that got thrown during handler execution * @return a corresponding {@code ModelAndView} to forward to, or {@code null} for default processing */ + @Nullable protected abstract ModelAndView doResolveException(HttpServletRequest request, - HttpServletResponse response, Object handler, Exception ex); + HttpServletResponse response, @Nullable Object handler, Exception ex); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMapping.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMapping.java index ce3051d5c7..0ff7fbcc74 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMapping.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMapping.java @@ -28,6 +28,7 @@ import javax.servlet.http.HttpServletResponse; import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanFactoryUtils; import org.springframework.core.Ordered; +import org.springframework.lang.Nullable; import org.springframework.util.AntPathMatcher; import org.springframework.util.Assert; import org.springframework.util.PathMatcher; @@ -111,6 +112,7 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport * Return the default handler for this handler mapping, * or {@code null} if none. */ + @Nullable public Object getDefaultHandler() { return this.defaultHandler; } @@ -197,7 +199,7 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport * @see org.springframework.web.servlet.HandlerInterceptor * @see org.springframework.web.context.request.WebRequestInterceptor */ - public void setInterceptors(Object... interceptors) { + public void setInterceptors(@Nullable Object... interceptors) { this.interceptors.addAll(Arrays.asList(interceptors)); } @@ -320,6 +322,7 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport * Return the adapted interceptors as {@link HandlerInterceptor} array. * @return the array of {@link HandlerInterceptor}s, or {@code null} if none */ + @Nullable protected final HandlerInterceptor[] getAdaptedInterceptors() { int count = this.adaptedInterceptors.size(); return (count > 0 ? this.adaptedInterceptors.toArray(new HandlerInterceptor[count]) : null); @@ -329,6 +332,7 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport * Return all configured {@link MappedInterceptor}s as an array. * @return the array of {@link MappedInterceptor}s, or {@code null} if none */ + @Nullable protected final MappedInterceptor[] getMappedInterceptors() { List mappedInterceptors = new ArrayList<>(); for (HandlerInterceptor interceptor : this.adaptedInterceptors) { @@ -389,6 +393,7 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport * @return the corresponding handler instance, or {@code null} if none found * @throws Exception if there is an internal error */ + @Nullable protected abstract Object getHandlerInternal(HttpServletRequest request) throws Exception; /** @@ -437,6 +442,7 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport * @return the CORS configuration for the handler or {@code null}. * @since 4.2 */ + @Nullable protected CorsConfiguration getCorsConfiguration(Object handler, HttpServletRequest request) { if (handler instanceof HandlerExecutionChain) { handler = ((HandlerExecutionChain) handler).getHandler(); @@ -460,7 +466,7 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport * @since 4.2 */ protected HandlerExecutionChain getCorsHandlerExecutionChain(HttpServletRequest request, - HandlerExecutionChain chain, CorsConfiguration config) { + HandlerExecutionChain chain, @Nullable CorsConfiguration config) { if (CorsUtils.isPreFlightRequest(request)) { HandlerInterceptor[] interceptors = chain.getInterceptors(); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMethodExceptionResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMethodExceptionResolver.java index 7f9bc06665..70bf496260 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMethodExceptionResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMethodExceptionResolver.java @@ -19,6 +19,7 @@ package org.springframework.web.servlet.handler; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.springframework.lang.Nullable; import org.springframework.web.method.HandlerMethod; import org.springframework.web.servlet.ModelAndView; @@ -73,7 +74,8 @@ public abstract class AbstractHandlerMethodExceptionResolver extends AbstractHan * @param ex the exception that got thrown during handler execution * @return a corresponding ModelAndView to forward to, or {@code null} for default processing */ + @Nullable protected abstract ModelAndView doResolveHandlerMethodException( - HttpServletRequest request, HttpServletResponse response, HandlerMethod handlerMethod, Exception ex); + HttpServletRequest request, HttpServletResponse response, @Nullable HandlerMethod handlerMethod, Exception ex); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMethodMapping.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMethodMapping.java index df5257e1f0..1fa77960a9 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMethodMapping.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMethodMapping.java @@ -28,6 +28,7 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.locks.ReentrantReadWriteLock; + import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; @@ -35,6 +36,7 @@ import org.springframework.aop.support.AopUtils; import org.springframework.beans.factory.BeanFactoryUtils; import org.springframework.beans.factory.InitializingBean; import org.springframework.core.MethodIntrospector; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.LinkedMultiValueMap; @@ -118,6 +120,7 @@ public abstract class AbstractHandlerMethodMapping extends AbstractHandlerMap /** * Return the configured naming strategy or {@code null}. */ + @Nullable public HandlerMethodMappingNamingStrategy getNamingStrategy() { return this.namingStrategy; } @@ -142,6 +145,7 @@ public abstract class AbstractHandlerMethodMapping extends AbstractHandlerMap * list will never be modified and is safe to iterate. * @see #setHandlerMethodMappingNamingStrategy */ + @Nullable public List getHandlerMethodsForMappingName(String mappingName) { return this.mappingRegistry.getHandlerMethodsByMappingName(mappingName); } @@ -286,6 +290,7 @@ public abstract class AbstractHandlerMethodMapping extends AbstractHandlerMap /** * Extract and return the CORS configuration for the mapping. */ + @Nullable protected CorsConfiguration initCorsConfiguration(Object handler, Method method, T mapping) { return null; } @@ -336,6 +341,7 @@ public abstract class AbstractHandlerMethodMapping extends AbstractHandlerMap * @see #handleMatch(Object, String, HttpServletRequest) * @see #handleNoMatch(Set, String, HttpServletRequest) */ + @Nullable protected HandlerMethod lookupHandlerMethod(String lookupPath, HttpServletRequest request) throws Exception { List matches = new ArrayList(); List directPathMatches = this.mappingRegistry.getMappingsByUrl(lookupPath); @@ -401,6 +407,7 @@ public abstract class AbstractHandlerMethodMapping extends AbstractHandlerMap * @param request the current request * @throws ServletException in case of errors */ + @Nullable protected HandlerMethod handleNoMatch(Set mappings, String lookupPath, HttpServletRequest request) throws Exception { @@ -441,6 +448,7 @@ public abstract class AbstractHandlerMethodMapping extends AbstractHandlerMap * declaring class * @return the mapping, or {@code null} if the method is not mapped */ + @Nullable protected abstract T getMappingForMethod(Method method, Class handlerType); /** @@ -455,6 +463,7 @@ public abstract class AbstractHandlerMethodMapping extends AbstractHandlerMap * @param request the current HTTP servlet request * @return the match, or {@code null} if the mapping doesn't match */ + @Nullable protected abstract T getMatchingMapping(T mapping, HttpServletRequest request); /** diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractUrlHandlerMapping.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractUrlHandlerMapping.java index 2b05738c89..9982b52341 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractUrlHandlerMapping.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractUrlHandlerMapping.java @@ -22,10 +22,12 @@ import java.util.Comparator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; + import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.beans.BeansException; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.web.servlet.HandlerExecutionChain; @@ -73,6 +75,7 @@ public abstract class AbstractUrlHandlerMapping extends AbstractHandlerMapping i * Return the root handler for this handler mapping (registered for "/"), * or {@code null} if none. */ + @Nullable public Object getRootHandler() { return this.rootHandler; } @@ -113,6 +116,7 @@ public abstract class AbstractUrlHandlerMapping extends AbstractHandlerMapping i * @return the handler instance, or {@code null} if none found */ @Override + @Nullable protected Object getHandlerInternal(HttpServletRequest request) throws Exception { String lookupPath = getUrlPathHelper().getLookupPathForRequest(request); Object handler = lookupHandler(lookupPath, request); @@ -158,6 +162,7 @@ public abstract class AbstractUrlHandlerMapping extends AbstractHandlerMapping i * @see #exposePathWithinMapping * @see org.springframework.util.AntPathMatcher */ + @Nullable protected Object lookupHandler(String urlPath, HttpServletRequest request) throws Exception { // Direct match? Object handler = this.handlerMap.get(urlPath); @@ -255,7 +260,7 @@ public abstract class AbstractUrlHandlerMapping extends AbstractHandlerMapping i * @return the final handler object */ protected Object buildPathExposingHandler(Object rawHandler, String bestMatchingPattern, - String pathWithinMapping, Map uriTemplateVariables) { + String pathWithinMapping, @Nullable Map uriTemplateVariables) { HandlerExecutionChain chain = new HandlerExecutionChain(rawHandler); chain.addInterceptor(new PathExposingHandlerInterceptor(bestMatchingPattern, pathWithinMapping)); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/HandlerMappingIntrospector.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/HandlerMappingIntrospector.java index 21a815ab64..4b38e361a8 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/HandlerMappingIntrospector.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/HandlerMappingIntrospector.java @@ -21,6 +21,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Properties; + import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequestWrapper; @@ -30,6 +31,7 @@ import org.springframework.core.annotation.AnnotationAwareOrderComparator; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; import org.springframework.core.io.support.PropertiesLoaderUtils; +import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.util.StringUtils; import org.springframework.web.cors.CorsConfiguration; @@ -125,6 +127,7 @@ public class HandlerMappingIntrospector implements CorsConfigurationSource { * @return the resolved matcher, or {@code null} * @throws Exception if any of the HandlerMapping's raise an exception */ + @Nullable public MatchableHandlerMapping getMatchableHandlerMapping(HttpServletRequest request) throws Exception { HttpServletRequest wrapper = new RequestAttributeChangeIgnoringWrapper(request); for (HandlerMapping handlerMapping : this.handlerMappings) { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/MappedInterceptor.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/MappedInterceptor.java index a238d537ea..9022c79242 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/MappedInterceptor.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/MappedInterceptor.java @@ -19,6 +19,7 @@ package org.springframework.web.servlet.handler; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.springframework.lang.Nullable; import org.springframework.util.PathMatcher; import org.springframework.web.context.request.WebRequestInterceptor; import org.springframework.web.servlet.HandlerInterceptor; @@ -57,7 +58,7 @@ public final class MappedInterceptor implements HandlerInterceptor { * @param includePatterns the path patterns to map with a {@code null} value matching to all paths * @param interceptor the HandlerInterceptor instance to map to the given patterns */ - public MappedInterceptor(String[] includePatterns, HandlerInterceptor interceptor) { + public MappedInterceptor(@Nullable String[] includePatterns, HandlerInterceptor interceptor) { this(includePatterns, null, interceptor); } @@ -67,7 +68,7 @@ public final class MappedInterceptor implements HandlerInterceptor { * @param excludePatterns the path patterns to exclude * @param interceptor the HandlerInterceptor instance to map to the given patterns */ - public MappedInterceptor(String[] includePatterns, String[] excludePatterns, HandlerInterceptor interceptor) { + public MappedInterceptor(@Nullable String[] includePatterns, String[] excludePatterns, HandlerInterceptor interceptor) { this.includePatterns = includePatterns; this.excludePatterns = excludePatterns; this.interceptor = interceptor; @@ -79,7 +80,7 @@ public final class MappedInterceptor implements HandlerInterceptor { * @param includePatterns the path patterns to map with a {@code null} value matching to all paths * @param interceptor the WebRequestInterceptor instance to map to the given patterns */ - public MappedInterceptor(String[] includePatterns, WebRequestInterceptor interceptor) { + public MappedInterceptor(@Nullable String[] includePatterns, WebRequestInterceptor interceptor) { this(includePatterns, null, interceptor); } @@ -88,7 +89,7 @@ public final class MappedInterceptor implements HandlerInterceptor { * @param includePatterns the path patterns to map with a {@code null} value matching to all paths * @param interceptor the WebRequestInterceptor instance to map to the given patterns */ - public MappedInterceptor(String[] includePatterns, String[] excludePatterns, WebRequestInterceptor interceptor) { + public MappedInterceptor(@Nullable String[] includePatterns, String[] excludePatterns, WebRequestInterceptor interceptor) { this(includePatterns, excludePatterns, new WebRequestHandlerInterceptorAdapter(interceptor)); } @@ -109,6 +110,7 @@ public final class MappedInterceptor implements HandlerInterceptor { /** * The configured PathMatcher, or {@code null}. */ + @Nullable public PathMatcher getPathMatcher() { return this.pathMatcher; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/MatchableHandlerMapping.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/MatchableHandlerMapping.java index af5788c7d8..b617e00e83 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/MatchableHandlerMapping.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/MatchableHandlerMapping.java @@ -18,6 +18,7 @@ package org.springframework.web.servlet.handler; import javax.servlet.http.HttpServletRequest; +import org.springframework.lang.Nullable; import org.springframework.web.servlet.HandlerMapping; /** @@ -37,6 +38,7 @@ public interface MatchableHandlerMapping extends HandlerMapping { * @param pattern the pattern to match * @return the result from request matching, or {@code null} if none */ + @Nullable RequestMatchResult match(HttpServletRequest request, String pattern); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/SimpleMappingExceptionResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/SimpleMappingExceptionResolver.java index ff698d3160..1b4be234f5 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/SimpleMappingExceptionResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/SimpleMappingExceptionResolver.java @@ -21,9 +21,11 @@ import java.util.Enumeration; import java.util.HashMap; import java.util.Map; import java.util.Properties; + import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.springframework.lang.Nullable; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.util.WebUtils; @@ -153,7 +155,7 @@ public class SimpleMappingExceptionResolver extends AbstractHandlerExceptionReso * for not exposing an exception attribute at all. * @see #DEFAULT_EXCEPTION_ATTRIBUTE */ - public void setExceptionAttribute(String exceptionAttribute) { + public void setExceptionAttribute(@Nullable String exceptionAttribute) { this.exceptionAttribute = exceptionAttribute; } @@ -201,6 +203,7 @@ public class SimpleMappingExceptionResolver extends AbstractHandlerExceptionReso * @param request current HTTP request (useful for obtaining metadata) * @return the resolved view name, or {@code null} if excluded or none found */ + @Nullable protected String determineViewName(Exception ex, HttpServletRequest request) { String viewName = null; if (this.excludedExceptions != null) { @@ -232,6 +235,7 @@ public class SimpleMappingExceptionResolver extends AbstractHandlerExceptionReso * @return the view name, or {@code null} if none found * @see #setExceptionMappings */ + @Nullable protected String findMatchingViewName(Properties exceptionMappings, Exception ex) { String viewName = null; String dominantMapping = null; @@ -287,6 +291,7 @@ public class SimpleMappingExceptionResolver extends AbstractHandlerExceptionReso * @see #setDefaultStatusCode * @see #applyStatusCodeIfPossible */ + @Nullable protected Integer determineStatusCode(HttpServletRequest request, String viewName) { if (this.statusCodes.containsKey(viewName)) { return this.statusCodes.get(viewName); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/package-info.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/package-info.java index 3b64fa913a..b4eec2d094 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/package-info.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/package-info.java @@ -2,4 +2,7 @@ * Provides standard HandlerMapping implementations, * including abstract base classes for custom implementations. */ +@NonNullApi package org.springframework.web.servlet.handler; + +import org.springframework.lang.NonNullApi; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/AbstractLocaleContextResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/AbstractLocaleContextResolver.java index f3ab7a1f4b..33b8b27bac 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/AbstractLocaleContextResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/AbstractLocaleContextResolver.java @@ -22,6 +22,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.context.i18n.SimpleLocaleContext; +import org.springframework.lang.Nullable; import org.springframework.web.servlet.LocaleContextResolver; /** @@ -51,6 +52,7 @@ public abstract class AbstractLocaleContextResolver extends AbstractLocaleResolv /** * Return the default TimeZone that this resolver is supposed to fall back to, if any. */ + @Nullable public TimeZone getDefaultTimeZone() { return this.defaultTimeZone; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/AbstractLocaleResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/AbstractLocaleResolver.java index c5fa0d7ba4..2728279c38 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/AbstractLocaleResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/AbstractLocaleResolver.java @@ -18,6 +18,7 @@ package org.springframework.web.servlet.i18n; import java.util.Locale; +import org.springframework.lang.Nullable; import org.springframework.web.servlet.LocaleResolver; /** @@ -43,6 +44,7 @@ public abstract class AbstractLocaleResolver implements LocaleResolver { /** * Return the default Locale that this resolver is supposed to fall back to, if any. */ + @Nullable protected Locale getDefaultLocale() { return this.defaultLocale; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/AcceptHeaderLocaleResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/AcceptHeaderLocaleResolver.java index c62fcef8a9..a755e789d1 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/AcceptHeaderLocaleResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/AcceptHeaderLocaleResolver.java @@ -23,6 +23,7 @@ import java.util.Locale; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.springframework.lang.Nullable; import org.springframework.web.servlet.LocaleResolver; /** @@ -84,6 +85,7 @@ public class AcceptHeaderLocaleResolver implements LocaleResolver { * The configured default locale, if any. * @since 4.3 */ + @Nullable public Locale getDefaultLocale() { return this.defaultLocale; } @@ -111,6 +113,7 @@ public class AcceptHeaderLocaleResolver implements LocaleResolver { return (supportedLocales.isEmpty() || supportedLocales.contains(locale)); } + @Nullable private Locale findSupportedLocale(HttpServletRequest request) { Enumeration requestLocales = request.getLocales(); while (requestLocales.hasMoreElements()) { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/CookieLocaleResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/CookieLocaleResolver.java index 5ae5652c40..c2e366e296 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/CookieLocaleResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/CookieLocaleResolver.java @@ -18,6 +18,7 @@ package org.springframework.web.servlet.i18n; import java.util.Locale; import java.util.TimeZone; + import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -25,6 +26,7 @@ import javax.servlet.http.HttpServletResponse; import org.springframework.context.i18n.LocaleContext; import org.springframework.context.i18n.SimpleLocaleContext; import org.springframework.context.i18n.TimeZoneAwareLocaleContext; +import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; import org.springframework.web.servlet.LocaleContextResolver; import org.springframework.web.servlet.LocaleResolver; @@ -131,6 +133,7 @@ public class CookieLocaleResolver extends CookieGenerator implements LocaleConte * Return the fixed Locale that this resolver will return if no cookie found, * if any. */ + @Nullable protected Locale getDefaultLocale() { return this.defaultLocale; } @@ -148,6 +151,7 @@ public class CookieLocaleResolver extends CookieGenerator implements LocaleConte * if any. * @since 4.0 */ + @Nullable protected TimeZone getDefaultTimeZone() { return this.defaultTimeZone; } @@ -283,6 +287,7 @@ public class CookieLocaleResolver extends CookieGenerator implements LocaleConte * @see #setDefaultLocale * @see javax.servlet.http.HttpServletRequest#getLocale() */ + @Nullable protected Locale determineDefaultLocale(HttpServletRequest request) { Locale defaultLocale = getDefaultLocale(); if (defaultLocale == null) { @@ -300,6 +305,7 @@ public class CookieLocaleResolver extends CookieGenerator implements LocaleConte * @return the default time zone (or {@code null} if none defined) * @see #setDefaultTimeZone */ + @Nullable protected TimeZone determineDefaultTimeZone(HttpServletRequest request) { return getDefaultTimeZone(); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/SessionLocaleResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/SessionLocaleResolver.java index 7291b47a58..343d6e6ce5 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/SessionLocaleResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/SessionLocaleResolver.java @@ -18,11 +18,13 @@ package org.springframework.web.servlet.i18n; import java.util.Locale; import java.util.TimeZone; + import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.context.i18n.LocaleContext; import org.springframework.context.i18n.TimeZoneAwareLocaleContext; +import org.springframework.lang.Nullable; import org.springframework.web.util.WebUtils; /** @@ -178,6 +180,7 @@ public class SessionLocaleResolver extends AbstractLocaleContextResolver { * @return the default time zone (or {@code null} if none defined) * @see #setDefaultTimeZone */ + @Nullable protected TimeZone determineDefaultTimeZone(HttpServletRequest request) { return getDefaultTimeZone(); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/package-info.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/package-info.java index 24539c7a12..7ba5d0ca41 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/package-info.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/package-info.java @@ -3,4 +3,7 @@ * Provides standard LocaleResolver implementations, * and a HandlerInterceptor for locale changes. */ +@NonNullApi package org.springframework.web.servlet.i18n; + +import org.springframework.lang.NonNullApi; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/AbstractController.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/AbstractController.java index c37e656a7e..e742af2e42 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/AbstractController.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/AbstractController.java @@ -21,6 +21,7 @@ import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import org.springframework.http.HttpMethod; +import org.springframework.lang.Nullable; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.support.WebContentGenerator; import org.springframework.web.util.WebUtils; @@ -179,6 +180,7 @@ public abstract class AbstractController extends WebContentGenerator implements * The contract is the same as for {@code handleRequest}. * @see #handleRequest */ + @Nullable protected abstract ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/Controller.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/Controller.java index f4f6bc88d7..c083dd5697 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/Controller.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/Controller.java @@ -19,6 +19,7 @@ package org.springframework.web.servlet.mvc; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.springframework.lang.Nullable; import org.springframework.web.servlet.ModelAndView; /** @@ -119,6 +120,7 @@ public interface Controller { * @return a ModelAndView to render, or {@code null} if handled directly * @throws Exception in case of errors */ + @Nullable ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/ParameterizableViewController.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/ParameterizableViewController.java index 5d512887dd..ca1c5e12cd 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/ParameterizableViewController.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/ParameterizableViewController.java @@ -21,6 +21,7 @@ import javax.servlet.http.HttpServletResponse; import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; +import org.springframework.lang.Nullable; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.View; import org.springframework.web.servlet.support.RequestContextUtils; @@ -62,6 +63,7 @@ public class ParameterizableViewController extends AbstractController { * Return the name of the view to delegate to, or {@code null} if using a * View instance. */ + @Nullable public String getViewName() { return (this.view instanceof String ? (String) this.view : null); } @@ -80,6 +82,7 @@ public class ParameterizableViewController extends AbstractController { * to be resolved by the DispatcherServlet via a ViewResolver. * @since 4.1 */ + @Nullable public View getView() { return (this.view instanceof View ? (View) this.view : null); } @@ -103,6 +106,7 @@ public class ParameterizableViewController extends AbstractController { * Return the configured HTTP status code or {@code null}. * @since 4.1 */ + @Nullable public HttpStatus getStatusCode() { return this.statusCode; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/WebContentInterceptor.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/WebContentInterceptor.java index 879d78eebc..7466661585 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/WebContentInterceptor.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/WebContentInterceptor.java @@ -26,6 +26,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.http.CacheControl; +import org.springframework.lang.Nullable; import org.springframework.util.AntPathMatcher; import org.springframework.util.Assert; import org.springframework.util.PathMatcher; @@ -214,6 +215,7 @@ public class WebContentInterceptor extends WebContentGenerator implements Handle * @return the associated {@code CacheControl}, or {@code null} if not found * @see org.springframework.util.AntPathMatcher */ + @Nullable protected CacheControl lookupCacheControl(String urlPath) { // Direct match? CacheControl cacheControl = this.cacheControlMappings.get(urlPath); @@ -238,6 +240,7 @@ public class WebContentInterceptor extends WebContentGenerator implements Handle * @return the cacheSeconds integer value, or {@code null} if not found * @see org.springframework.util.AntPathMatcher */ + @Nullable protected Integer lookupCacheSeconds(String urlPath) { // Direct match? Integer cacheSeconds = this.cacheMappings.get(urlPath); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/annotation/ResponseStatusExceptionResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/annotation/ResponseStatusExceptionResolver.java index b6fd282b0b..51fec27c76 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/annotation/ResponseStatusExceptionResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/annotation/ResponseStatusExceptionResolver.java @@ -17,6 +17,7 @@ package org.springframework.web.servlet.mvc.annotation; import java.io.IOException; + import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -24,6 +25,7 @@ import org.springframework.context.MessageSource; import org.springframework.context.MessageSourceAware; import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.core.annotation.AnnotatedElementUtils; +import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.server.ResponseStatusException; @@ -101,7 +103,7 @@ public class ResponseStatusExceptionResolver extends AbstractHandlerExceptionRes * @return an empty ModelAndView, i.e. exception resolved */ protected ModelAndView resolveResponseStatus(ResponseStatus responseStatus, HttpServletRequest request, - HttpServletResponse response, Object handler, Exception ex) throws Exception { + HttpServletResponse response, @Nullable Object handler, Exception ex) throws Exception { int statusCode = responseStatus.code().value(); String reason = responseStatus.reason(); @@ -121,7 +123,7 @@ public class ResponseStatusExceptionResolver extends AbstractHandlerExceptionRes * @since 5.0 */ protected ModelAndView resolveResponseStatusException(ResponseStatusException ex, - HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { + HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws Exception { int statusCode = ex.getStatus().value(); String reason = ex.getReason(); @@ -139,7 +141,7 @@ public class ResponseStatusExceptionResolver extends AbstractHandlerExceptionRes * @param response current HTTP response * @since 5.0 */ - protected ModelAndView applyStatusAndReason(int statusCode, String reason, HttpServletResponse response) + protected ModelAndView applyStatusAndReason(int statusCode, @Nullable String reason, HttpServletResponse response) throws IOException { if (!StringUtils.hasLength(reason)) { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/annotation/package-info.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/annotation/package-info.java index e24566b816..a1572226f9 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/annotation/package-info.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/annotation/package-info.java @@ -1,4 +1,7 @@ /** * Support package for annotation-based Servlet MVC controllers. */ +@NonNullApi package org.springframework.web.servlet.mvc.annotation; + +import org.springframework.lang.NonNullApi; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/CompositeRequestCondition.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/CompositeRequestCondition.java index 97949e2167..cf7fe38924 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/CompositeRequestCondition.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/CompositeRequestCondition.java @@ -20,8 +20,10 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; + import javax.servlet.http.HttpServletRequest; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; @@ -49,7 +51,7 @@ public class CompositeRequestCondition extends AbstractRequestCondition... requestConditions) { + public CompositeRequestCondition(@Nullable RequestCondition... requestConditions) { this.requestConditions = wrap(requestConditions); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/ConsumesRequestCondition.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/ConsumesRequestCondition.java index 305012b21a..8b156cd231 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/ConsumesRequestCondition.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/ConsumesRequestCondition.java @@ -23,6 +23,7 @@ import java.util.Iterator; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; + import javax.servlet.http.HttpServletRequest; import org.springframework.http.InvalidMediaTypeException; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/RequestCondition.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/RequestCondition.java index 542e1a2d74..3a199cd808 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/RequestCondition.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/RequestCondition.java @@ -18,6 +18,8 @@ package org.springframework.web.servlet.mvc.condition; import javax.servlet.http.HttpServletRequest; +import org.springframework.lang.Nullable; + /** * Contract for request mapping conditions. * @@ -55,6 +57,7 @@ public interface RequestCondition { * empty content thus not causing a failure to match. * @return a condition instance in case of a match or {@code null} otherwise. */ + @Nullable T getMatchingCondition(HttpServletRequest request); /** diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/RequestConditionHolder.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/RequestConditionHolder.java index 4b21b39efa..39132536c3 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/RequestConditionHolder.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/RequestConditionHolder.java @@ -18,8 +18,11 @@ package org.springframework.web.servlet.mvc.condition; import java.util.Collection; import java.util.Collections; + import javax.servlet.http.HttpServletRequest; +import org.springframework.lang.Nullable; + /** * A holder for a {@link RequestCondition} useful when the type of the request * condition is not known ahead of time, e.g. custom condition. Since this @@ -44,7 +47,7 @@ public final class RequestConditionHolder extends AbstractRequestCondition requestCondition) { + public RequestConditionHolder(@Nullable RequestCondition requestCondition) { this.condition = (RequestCondition) requestCondition; } @@ -52,6 +55,7 @@ public final class RequestConditionHolder extends AbstractRequestCondition getCondition() { return this.condition; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/package-info.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/package-info.java index f6180f4226..d8e5ccdd7f 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/package-info.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/package-info.java @@ -1,4 +1,7 @@ /** * Common MVC logic for matching incoming requests based on conditions. */ +@NonNullApi package org.springframework.web.servlet.mvc.condition; + +import org.springframework.lang.NonNullApi; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/AbstractHandlerMethodAdapter.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/AbstractHandlerMethodAdapter.java index 803b595d4b..677e40b007 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/AbstractHandlerMethodAdapter.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/AbstractHandlerMethodAdapter.java @@ -20,6 +20,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.core.Ordered; +import org.springframework.lang.Nullable; import org.springframework.web.method.HandlerMethod; import org.springframework.web.servlet.HandlerAdapter; import org.springframework.web.servlet.ModelAndView; @@ -95,6 +96,7 @@ public abstract class AbstractHandlerMethodAdapter extends WebContentGenerator i * or {@code null} if the request has been handled directly * @throws Exception in case of errors */ + @Nullable protected abstract ModelAndView handleInternal(HttpServletRequest request, HttpServletResponse response, HandlerMethod handlerMethod) throws Exception; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/RequestMappingInfo.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/RequestMappingInfo.java index 88fb9b45dd..2f6670c195 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/RequestMappingInfo.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/RequestMappingInfo.java @@ -17,9 +17,11 @@ package org.springframework.web.servlet.mvc.method; import java.util.List; + import javax.servlet.http.HttpServletRequest; import org.springframework.http.HttpMethod; +import org.springframework.lang.Nullable; import org.springframework.util.PathMatcher; import org.springframework.util.StringUtils; import org.springframework.web.accept.ContentNegotiationManager; @@ -105,6 +107,7 @@ public final class RequestMappingInfo implements RequestCondition getCustomCondition() { return this.customConditionHolder.getCondition(); } @@ -532,6 +536,7 @@ public final class RequestMappingInfo implements RequestCondition Object readWithMessageConverters(NativeWebRequest webRequest, MethodParameter parameter, + protected Object readWithMessageConverters(NativeWebRequest webRequest, @Nullable MethodParameter parameter, Type paramType) throws IOException, HttpMediaTypeNotSupportedException, HttpMessageNotReadableException { HttpInputMessage inputMessage = createInputMessage(webRequest); @@ -157,7 +159,8 @@ public abstract class AbstractMessageConverterMethodArgumentResolver implements * @throws HttpMediaTypeNotSupportedException if no suitable message converter is found */ @SuppressWarnings("unchecked") - protected Object readWithMessageConverters(HttpInputMessage inputMessage, MethodParameter parameter, + @Nullable + protected Object readWithMessageConverters(HttpInputMessage inputMessage, @Nullable MethodParameter parameter, Type targetType) throws IOException, HttpMediaTypeNotSupportedException, HttpMessageNotReadableException { MediaType contentType; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ExceptionHandlerExceptionResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ExceptionHandlerExceptionResolver.java index 26434dc83e..f93a785aad 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ExceptionHandlerExceptionResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ExceptionHandlerExceptionResolver.java @@ -24,6 +24,7 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.concurrent.ConcurrentHashMap; + import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -37,6 +38,7 @@ import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.StringHttpMessageConverter; import org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter; import org.springframework.http.converter.xml.SourceHttpMessageConverter; +import org.springframework.lang.Nullable; import org.springframework.ui.ModelMap; import org.springframework.web.accept.ContentNegotiationManager; import org.springframework.web.bind.annotation.ControllerAdvice; @@ -121,6 +123,7 @@ public class ExceptionHandlerExceptionResolver extends AbstractHandlerMethodExce /** * Return the custom argument resolvers, or {@code null}. */ + @Nullable public List getCustomArgumentResolvers() { return this.customArgumentResolvers; } @@ -143,6 +146,7 @@ public class ExceptionHandlerExceptionResolver extends AbstractHandlerMethodExce * Return the configured argument resolvers, or possibly {@code null} if * not initialized yet via {@link #afterPropertiesSet()}. */ + @Nullable public HandlerMethodArgumentResolverComposite getArgumentResolvers() { return this.argumentResolvers; } @@ -159,6 +163,7 @@ public class ExceptionHandlerExceptionResolver extends AbstractHandlerMethodExce /** * Return the custom return value handlers, or {@code null}. */ + @Nullable public List getCustomReturnValueHandlers() { return this.customReturnValueHandlers; } @@ -181,6 +186,7 @@ public class ExceptionHandlerExceptionResolver extends AbstractHandlerMethodExce * Return the configured handlers, or possibly {@code null} if not * initialized yet via {@link #afterPropertiesSet()}. */ + @Nullable public HandlerMethodReturnValueHandlerComposite getReturnValueHandlers() { return this.returnValueHandlers; } @@ -423,7 +429,8 @@ public class ExceptionHandlerExceptionResolver extends AbstractHandlerMethodExce * @param exception the raised exception * @return a method to handle the exception, or {@code null} */ - protected ServletInvocableHandlerMethod getExceptionHandlerMethod(HandlerMethod handlerMethod, Exception exception) { + @Nullable + protected ServletInvocableHandlerMethod getExceptionHandlerMethod(@Nullable HandlerMethod handlerMethod, Exception exception) { Class handlerType = (handlerMethod != null ? handlerMethod.getBeanType() : null); if (handlerMethod != null) { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ExtendedServletRequestDataBinder.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ExtendedServletRequestDataBinder.java index e559e99317..32c344576a 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ExtendedServletRequestDataBinder.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ExtendedServletRequestDataBinder.java @@ -18,9 +18,11 @@ package org.springframework.web.servlet.mvc.method.annotation; import java.util.Map; import java.util.Map.Entry; + import javax.servlet.ServletRequest; import org.springframework.beans.MutablePropertyValues; +import org.springframework.lang.Nullable; import org.springframework.web.bind.ServletRequestDataBinder; import org.springframework.web.servlet.HandlerMapping; @@ -39,7 +41,7 @@ public class ExtendedServletRequestDataBinder extends ServletRequestDataBinder { * if the binder is just used to convert a plain parameter value) * @see #DEFAULT_OBJECT_NAME */ - public ExtendedServletRequestDataBinder(Object target) { + public ExtendedServletRequestDataBinder(@Nullable Object target) { super(target); } @@ -50,7 +52,7 @@ public class ExtendedServletRequestDataBinder extends ServletRequestDataBinder { * @param objectName the name of the target object * @see #DEFAULT_OBJECT_NAME */ - public ExtendedServletRequestDataBinder(Object target, String objectName) { + public ExtendedServletRequestDataBinder(@Nullable Object target, String objectName) { super(target, objectName); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/HttpEntityMethodProcessor.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/HttpEntityMethodProcessor.java index d03c606d80..d2038bd8a9 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/HttpEntityMethodProcessor.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/HttpEntityMethodProcessor.java @@ -36,6 +36,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.server.ServletServerHttpRequest; import org.springframework.http.server.ServletServerHttpResponse; +import org.springframework.lang.Nullable; import org.springframework.ui.ModelMap; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; @@ -142,6 +143,7 @@ public class HttpEntityMethodProcessor extends AbstractMessageConverterMethodPro } } + @Nullable private Type getHttpEntityType(MethodParameter parameter) { Assert.isAssignable(HttpEntity.class, parameter.getParameterType()); Type parameterType = parameter.getGenericParameterType(); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ModelAndViewMethodReturnValueHandler.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ModelAndViewMethodReturnValueHandler.java index 10ea402812..25786f460c 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ModelAndViewMethodReturnValueHandler.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ModelAndViewMethodReturnValueHandler.java @@ -17,6 +17,7 @@ package org.springframework.web.servlet.mvc.method.annotation; import org.springframework.core.MethodParameter; +import org.springframework.lang.Nullable; import org.springframework.util.PatternMatchUtils; import org.springframework.web.context.request.NativeWebRequest; import org.springframework.web.method.support.HandlerMethodReturnValueHandler; @@ -62,6 +63,7 @@ public class ModelAndViewMethodReturnValueHandler implements HandlerMethodReturn /** * The configured redirect patterns, if any. */ + @Nullable public String[] getRedirectPatterns() { return this.redirectPatterns; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/MvcUriComponentsBuilder.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/MvcUriComponentsBuilder.java index 8b0dd0e787..559d3dd7b9 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/MvcUriComponentsBuilder.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/MvcUriComponentsBuilder.java @@ -44,6 +44,7 @@ import org.springframework.core.MethodParameter; import org.springframework.core.ParameterNameDiscoverer; import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.core.annotation.SynthesizingMethodParameter; +import org.springframework.lang.Nullable; import org.springframework.objenesis.ObjenesisException; import org.springframework.objenesis.SpringObjenesis; import org.springframework.util.AntPathMatcher; @@ -489,6 +490,7 @@ public class MvcUriComponentsBuilder { }); } + @Nullable private static CompositeUriComponentsContributor getConfiguredUriComponentsContributor() { WebApplicationContext wac = getWebApplicationContext(); if (wac == null) { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ReactiveTypeHandler.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ReactiveTypeHandler.java index 1787960349..5326d1e640 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ReactiveTypeHandler.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ReactiveTypeHandler.java @@ -39,6 +39,7 @@ import org.springframework.core.task.TaskExecutor; import org.springframework.http.MediaType; import org.springframework.http.codec.ServerSentEvent; import org.springframework.http.server.ServerHttpResponse; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.util.MimeType; @@ -107,6 +108,7 @@ class ReactiveTypeHandler { * @return an emitter for streaming or {@code null} if handled internally * with a {@link DeferredResult}. */ + @Nullable public ResponseBodyEmitter handleValue(Object returnValue, MethodParameter returnType, ModelAndViewContainer mav, NativeWebRequest request) throws Exception { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestBodyAdvice.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestBodyAdvice.java index ee0be6504d..bd282e3f86 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestBodyAdvice.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestBodyAdvice.java @@ -22,6 +22,7 @@ import java.lang.reflect.Type; import org.springframework.core.MethodParameter; import org.springframework.http.HttpInputMessage; import org.springframework.http.converter.HttpMessageConverter; +import org.springframework.lang.Nullable; /** * Allows customizing the request before its body is read and converted into an @@ -60,7 +61,8 @@ public interface RequestBodyAdvice { * @return the value to use or {@code null} which may then raise an * {@code HttpMessageNotReadableException} if the argument is required. */ - Object handleEmptyBody(Object body, HttpInputMessage inputMessage, MethodParameter parameter, + @Nullable + Object handleEmptyBody(@Nullable Object body, HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, Class> converterType); /** diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapter.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapter.java index 36df1ef1d8..cfd8ec4ea9 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapter.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapter.java @@ -25,6 +25,7 @@ import java.util.Map.Entry; import java.util.Set; import java.util.concurrent.Callable; import java.util.concurrent.ConcurrentHashMap; + import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; @@ -46,6 +47,7 @@ import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.StringHttpMessageConverter; import org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter; import org.springframework.http.converter.xml.SourceHttpMessageConverter; +import org.springframework.lang.Nullable; import org.springframework.ui.ModelMap; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; @@ -197,6 +199,7 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter /** * Return the custom argument resolvers, or {@code null}. */ + @Nullable public List getCustomArgumentResolvers() { return this.customArgumentResolvers; } @@ -219,6 +222,7 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter * Return the configured argument resolvers, or possibly {@code null} if * not initialized yet via {@link #afterPropertiesSet()}. */ + @Nullable public List getArgumentResolvers() { return (this.argumentResolvers != null) ? this.argumentResolvers.getResolvers() : null; } @@ -240,6 +244,7 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter * Return the argument resolvers for {@code @InitBinder} methods, or possibly * {@code null} if not initialized yet via {@link #afterPropertiesSet()}. */ + @Nullable public List getInitBinderArgumentResolvers() { return (this.initBinderArgumentResolvers != null) ? this.initBinderArgumentResolvers.getResolvers() : null; } @@ -256,6 +261,7 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter /** * Return the custom return value handlers, or {@code null}. */ + @Nullable public List getCustomReturnValueHandlers() { return this.customReturnValueHandlers; } @@ -278,6 +284,7 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter * Return the configured handlers, or possibly {@code null} if not * initialized yet via {@link #afterPropertiesSet()}. */ + @Nullable public List getReturnValueHandlers() { return this.returnValueHandlers.getHandlers(); } @@ -303,6 +310,7 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter /** * Return the configured {@link ModelAndViewResolver}s, or {@code null}. */ + @Nullable public List getModelAndViewResolvers() { return modelAndViewResolvers; } @@ -364,6 +372,7 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter /** * Return the configured WebBindingInitializer, or {@code null} if none. */ + @Nullable public WebBindingInitializer getWebBindingInitializer() { return this.webBindingInitializer; } @@ -520,6 +529,7 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter /** * Return the owning factory of this bean instance, or {@code null} if none. */ + @Nullable protected ConfigurableBeanFactory getBeanFactory() { return this.beanFactory; } @@ -805,6 +815,7 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter * @since 4.2 * @see #createInvocableHandlerMethod(HandlerMethod) */ + @Nullable protected ModelAndView invokeHandlerMethod(HttpServletRequest request, HttpServletResponse response, HandlerMethod handlerMethod) throws Exception { @@ -944,6 +955,7 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter return new ServletRequestDataBinderFactory(binderMethods, getWebBindingInitializer()); } + @Nullable private ModelAndView getModelAndView(ModelAndViewContainer mavContainer, ModelFactory modelFactory, NativeWebRequest webRequest) throws Exception { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMapping.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMapping.java index c79facb1ab..223b933d77 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMapping.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMapping.java @@ -20,10 +20,12 @@ import java.lang.reflect.AnnotatedElement; import java.lang.reflect.Method; import java.util.List; import java.util.Set; + import javax.servlet.http.HttpServletRequest; import org.springframework.context.EmbeddedValueResolverAware; import org.springframework.core.annotation.AnnotatedElementUtils; +import org.springframework.lang.Nullable; import org.springframework.stereotype.Controller; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; @@ -219,6 +221,7 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi * @param handlerType the handler type for which to create the condition * @return the condition, or {@code null} */ + @Nullable protected RequestCondition getCustomTypeCondition(Class handlerType) { return null; } @@ -234,6 +237,7 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi * @param method the handler method for which to create the condition * @return the condition, or {@code null} */ + @Nullable protected RequestCondition getCustomMethodCondition(Method method) { return null; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ResponseBodyEmitter.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ResponseBodyEmitter.java index 43bad26837..de41ce1293 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ResponseBodyEmitter.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ResponseBodyEmitter.java @@ -22,6 +22,7 @@ import java.util.Set; import org.springframework.http.MediaType; import org.springframework.http.server.ServerHttpResponse; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; @@ -98,6 +99,7 @@ public class ResponseBodyEmitter { /** * Return the configured timeout value, if any. */ + @Nullable public Long getTimeout() { return this.timeout; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ResponseEntityExceptionHandler.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ResponseEntityExceptionHandler.java index d5718a3ee4..6b1d4cec5e 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ResponseEntityExceptionHandler.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ResponseEntityExceptionHandler.java @@ -34,6 +34,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.HttpMessageNotReadableException; import org.springframework.http.converter.HttpMessageNotWritableException; +import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; import org.springframework.validation.BindException; import org.springframework.web.HttpMediaTypeNotAcceptableException; @@ -446,6 +447,7 @@ public abstract class ResponseEntityExceptionHandler { * @return a {@code ResponseEntity} instance * @since 4.2.8 */ + @Nullable protected ResponseEntity handleAsyncRequestTimeoutException( AsyncRequestTimeoutException ex, HttpHeaders headers, HttpStatus status, WebRequest webRequest) { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletModelAttributeMethodProcessor.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletModelAttributeMethodProcessor.java index a59e0aa00f..2a8497a534 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletModelAttributeMethodProcessor.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletModelAttributeMethodProcessor.java @@ -18,12 +18,14 @@ package org.springframework.web.servlet.mvc.method.annotation; import java.util.Collections; import java.util.Map; + import javax.servlet.ServletRequest; import org.springframework.core.MethodParameter; import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.TypeDescriptor; import org.springframework.core.convert.converter.Converter; +import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; import org.springframework.validation.DataBinder; import org.springframework.web.bind.ServletRequestDataBinder; @@ -90,6 +92,7 @@ public class ServletModelAttributeMethodProcessor extends ModelAttributeMethodPr * @param request the current request * @return the request value to try to convert, or {@code null} if none */ + @Nullable protected String getRequestValueForAttribute(String attributeName, NativeWebRequest request) { Map variables = getUriTemplateVariables(request); String variableValue = variables.get(attributeName); @@ -124,7 +127,8 @@ public class ServletModelAttributeMethodProcessor extends ModelAttributeMethodPr * conversion found * @throws Exception */ - protected Object createAttributeFromRequestValue(String sourceValue, String attributeName, + @Nullable + protected Object createAttributeFromRequestValue(String sourceValue, @Nullable String attributeName, MethodParameter methodParam, WebDataBinderFactory binderFactory, NativeWebRequest request) throws Exception { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ViewNameMethodReturnValueHandler.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ViewNameMethodReturnValueHandler.java index 9601ce60e3..0130d963c7 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ViewNameMethodReturnValueHandler.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ViewNameMethodReturnValueHandler.java @@ -17,6 +17,7 @@ package org.springframework.web.servlet.mvc.method.annotation; import org.springframework.core.MethodParameter; +import org.springframework.lang.Nullable; import org.springframework.util.PatternMatchUtils; import org.springframework.web.context.request.NativeWebRequest; import org.springframework.web.method.support.HandlerMethodReturnValueHandler; @@ -62,6 +63,7 @@ public class ViewNameMethodReturnValueHandler implements HandlerMethodReturnValu /** * The configured redirect patterns, if any. */ + @Nullable public String[] getRedirectPatterns() { return this.redirectPatterns; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/package-info.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/package-info.java index 46c680b5ad..54c61e6a9e 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/package-info.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/package-info.java @@ -4,4 +4,7 @@ * {@link org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping} * and {@link org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter}. */ +@NonNullApi package org.springframework.web.servlet.mvc.method.annotation; + +import org.springframework.lang.NonNullApi; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/package-info.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/package-info.java index 14f9061926..8ba7aa6f12 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/package-info.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/package-info.java @@ -2,4 +2,7 @@ * Servlet-based infrastructure for handler method processing, * building on the {@code org.springframework.web.method} package. */ +@NonNullApi package org.springframework.web.servlet.mvc.method; + +import org.springframework.lang.NonNullApi; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/package-info.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/package-info.java index 7217100f44..0bfa4e40d1 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/package-info.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/package-info.java @@ -2,4 +2,7 @@ * Standard controller implementations for the Servlet MVC framework that comes with * Spring. Provides various controller styles, including an annotation-based model. */ +@NonNullApi package org.springframework.web.servlet.mvc; + +import org.springframework.lang.NonNullApi; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/support/DefaultHandlerExceptionResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/support/DefaultHandlerExceptionResolver.java index 80e61a3881..cbe0085576 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/support/DefaultHandlerExceptionResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/support/DefaultHandlerExceptionResolver.java @@ -18,6 +18,7 @@ package org.springframework.web.servlet.mvc.support; import java.io.IOException; import java.util.List; + import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -30,6 +31,7 @@ import org.springframework.core.Ordered; import org.springframework.http.MediaType; import org.springframework.http.converter.HttpMessageNotReadableException; import org.springframework.http.converter.HttpMessageNotWritableException; +import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; import org.springframework.validation.BindException; @@ -181,7 +183,7 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes * @throws IOException potentially thrown from response.sendError() */ protected ModelAndView handleHttpRequestMethodNotSupported(HttpRequestMethodNotSupportedException ex, - HttpServletRequest request, HttpServletResponse response, Object handler) throws IOException { + HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException { pageNotFoundLogger.warn(ex.getMessage()); String[] supportedMethods = ex.getSupportedMethods(); @@ -448,7 +450,7 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes * @since 4.0 */ protected ModelAndView handleNoHandlerFoundException(NoHandlerFoundException ex, - HttpServletRequest request, HttpServletResponse response, Object handler) throws IOException { + HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException { response.sendError(HttpServletResponse.SC_NOT_FOUND); return new ModelAndView(); @@ -467,7 +469,7 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes * @since 4.2.8 */ protected ModelAndView handleAsyncRequestTimeoutException(AsyncRequestTimeoutException ex, - HttpServletRequest request, HttpServletResponse response, Object handler) throws IOException { + HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException { if (!response.isCommitted()) { response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/support/RedirectAttributes.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/support/RedirectAttributes.java index e8952b58f4..1ac0887c6b 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/support/RedirectAttributes.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/support/RedirectAttributes.java @@ -19,6 +19,7 @@ package org.springframework.web.servlet.mvc.support; import java.util.Collection; import java.util.Map; +import org.springframework.lang.Nullable; import org.springframework.ui.Model; import org.springframework.web.servlet.FlashMap; @@ -76,7 +77,7 @@ public interface RedirectAttributes extends Model { * @param attributeName the attribute name; never {@code null} * @param attributeValue the attribute value; may be {@code null} */ - RedirectAttributes addFlashAttribute(String attributeName, Object attributeValue); + RedirectAttributes addFlashAttribute(String attributeName, @Nullable Object attributeValue); /** * Add the given flash storage using a diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/support/package-info.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/support/package-info.java index 4958b2b3c3..07460be108 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/support/package-info.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/support/package-info.java @@ -2,4 +2,7 @@ * Support package for MVC controllers. * Contains a special HandlerMapping for controller conventions. */ +@NonNullApi package org.springframework.web.servlet.mvc.support; + +import org.springframework.lang.NonNullApi; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/package-info.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/package-info.java index 19b495821b..359de4aa57 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/package-info.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/package-info.java @@ -7,4 +7,7 @@ * Expert One-On-One J2EE Design and Development * by Rod Johnson (Wrox, 2002). */ +@NonNullApi package org.springframework.web.servlet; + +import org.springframework.lang.NonNullApi; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/AbstractResourceResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/AbstractResourceResolver.java index 75afad31e9..d04fafe712 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/AbstractResourceResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/AbstractResourceResolver.java @@ -23,6 +23,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.core.io.Resource; +import org.springframework.lang.Nullable; /** * Base class for {@link org.springframework.web.servlet.resource.ResourceResolver} @@ -58,6 +59,7 @@ public abstract class AbstractResourceResolver implements ResourceResolver { } + @Nullable protected abstract Resource resolveResourceInternal(HttpServletRequest request, String requestPath, List locations, ResourceResolverChain chain); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/DefaultResourceTransformerChain.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/DefaultResourceTransformerChain.java index 7cbb46bfa1..8209d67472 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/DefaultResourceTransformerChain.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/DefaultResourceTransformerChain.java @@ -22,6 +22,7 @@ import java.util.List; import javax.servlet.http.HttpServletRequest; import org.springframework.core.io.Resource; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -71,6 +72,7 @@ class DefaultResourceTransformerChain implements ResourceTransformerChain { } } + @Nullable private ResourceTransformer getNext() { Assert.state(this.index <= this.transformers.size(), "Current index exceeds the number of configured ResourceTransformer's"); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/PathResourceResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/PathResourceResolver.java index 2119b7a7a0..9cd8beb2f5 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/PathResourceResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/PathResourceResolver.java @@ -20,11 +20,13 @@ import java.io.IOException; import java.net.URLDecoder; import java.util.Arrays; import java.util.List; + import javax.servlet.http.HttpServletRequest; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; import org.springframework.core.io.UrlResource; +import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; import org.springframework.web.context.support.ServletContextResource; @@ -85,6 +87,7 @@ public class PathResourceResolver extends AbstractResourceResolver { return (StringUtils.hasText(resourcePath) && getResource(resourcePath, locations) != null ? resourcePath : null); } + @Nullable private Resource getResource(String resourcePath, List locations) { for (Resource location : locations) { try { @@ -117,6 +120,7 @@ public class PathResourceResolver extends AbstractResourceResolver { * @param location the location to check * @return the resource, or {@code null} if none found */ + @Nullable protected Resource getResource(String resourcePath, Resource location) throws IOException { Resource resource = location.createRelative(resourcePath); if (resource.exists() && resource.isReadable()) { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandler.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandler.java index 1d268c1565..bea87e00dc 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandler.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandler.java @@ -22,6 +22,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; + import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -40,6 +41,7 @@ import org.springframework.http.converter.ResourceHttpMessageConverter; import org.springframework.http.converter.ResourceRegionHttpMessageConverter; import org.springframework.http.server.ServletServerHttpRequest; import org.springframework.http.server.ServletServerHttpResponse; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.util.ObjectUtils; @@ -391,6 +393,7 @@ public class ResourceHttpRequestHandler extends WebContentGenerator } } + @Nullable protected Resource getResource(HttpServletRequest request) throws IOException { String path = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE); if (path == null) { @@ -511,6 +514,7 @@ public class ResourceHttpRequestHandler extends WebContentGenerator * @param resource the resource to check * @return the corresponding media type, or {@code null} if none found */ + @Nullable protected MediaType getMediaType(HttpServletRequest request, Resource resource) { return this.contentNegotiationStrategy.getMediaTypeForResource(resource); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceResolver.java index d9a974129d..f1555287d0 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceResolver.java @@ -17,9 +17,11 @@ package org.springframework.web.servlet.resource; import java.util.List; + import javax.servlet.http.HttpServletRequest; import org.springframework.core.io.Resource; +import org.springframework.lang.Nullable; /** * A strategy for resolving a request to a server-side resource. @@ -45,6 +47,7 @@ public interface ResourceResolver { * @param chain the chain of remaining resolvers to delegate to * @return the resolved resource or {@code null} if unresolved */ + @Nullable Resource resolveResource(HttpServletRequest request, String requestPath, List locations, ResourceResolverChain chain); @@ -58,6 +61,7 @@ public interface ResourceResolver { * @param chain the chain of resolvers to delegate to * @return the resolved public URL path or {@code null} if unresolved */ + @Nullable String resolveUrlPath(String resourcePath, List locations, ResourceResolverChain chain); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceResolverChain.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceResolverChain.java index 65a03a2436..e12e49b90b 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceResolverChain.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceResolverChain.java @@ -17,9 +17,11 @@ package org.springframework.web.servlet.resource; import java.util.List; + import javax.servlet.http.HttpServletRequest; import org.springframework.core.io.Resource; +import org.springframework.lang.Nullable; /** * A contract for invoking a chain of {@link ResourceResolver}s where each resolver @@ -40,6 +42,7 @@ public interface ResourceResolverChain { * @param locations the locations to search in when looking up resources * @return the resolved resource or {@code null} if unresolved */ + @Nullable Resource resolveResource(HttpServletRequest request, String requestPath, List locations); /** @@ -51,6 +54,7 @@ public interface ResourceResolverChain { * @param locations the locations to search in when looking up resources * @return the resolved public URL path or {@code null} if unresolved */ + @Nullable String resolveUrlPath(String resourcePath, List locations); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceTransformerSupport.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceTransformerSupport.java index de6b775837..41a1255993 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceTransformerSupport.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceTransformerSupport.java @@ -20,6 +20,7 @@ import java.util.Collections; import javax.servlet.http.HttpServletRequest; import org.springframework.core.io.Resource; +import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; /** @@ -65,6 +66,7 @@ public abstract class ResourceTransformerSupport implements ResourceTransformer * @param transformerChain the transformer chain * @return the resolved URL or null */ + @Nullable protected String resolveUrlPath(String resourcePath, HttpServletRequest request, Resource resource, ResourceTransformerChain transformerChain) { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceUrlProvider.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceUrlProvider.java index bf74842dad..b75b37cde2 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceUrlProvider.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceUrlProvider.java @@ -32,6 +32,7 @@ import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationListener; import org.springframework.context.event.ContextRefreshedEvent; import org.springframework.core.annotation.AnnotationAwareOrderComparator; +import org.springframework.lang.Nullable; import org.springframework.util.AntPathMatcher; import org.springframework.util.PathMatcher; import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping; @@ -169,6 +170,7 @@ public class ResourceUrlProvider implements ApplicationListener matchingPatterns = new ArrayList<>(); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/WebJarsResourceResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/WebJarsResourceResolver.java index 71c2a490e5..d0253e4563 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/WebJarsResourceResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/WebJarsResourceResolver.java @@ -23,6 +23,7 @@ import javax.servlet.http.HttpServletRequest; import org.webjars.WebJarAssetLocator; import org.springframework.core.io.Resource; +import org.springframework.lang.Nullable; /** * A {@code ResourceResolver} that delegates to the chain to locate a resource and then @@ -98,6 +99,7 @@ public class WebJarsResourceResolver extends AbstractResourceResolver { return path; } + @Nullable protected String findWebJarResourcePath(String path) { int startOffset = (path.startsWith("/") ? 1 : 0); int endOffset = path.indexOf("/", 1); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/package-info.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/package-info.java index 04c78d3e50..89c174b3c6 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/package-info.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/package-info.java @@ -1,4 +1,7 @@ /** * Support classes for serving static resources. */ +@NonNullApi package org.springframework.web.servlet.resource; + +import org.springframework.lang.NonNullApi; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/support/AbstractAnnotationConfigDispatcherServletInitializer.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/support/AbstractAnnotationConfigDispatcherServletInitializer.java index 20b2b9e45b..0848544619 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/support/AbstractAnnotationConfigDispatcherServletInitializer.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/support/AbstractAnnotationConfigDispatcherServletInitializer.java @@ -16,6 +16,7 @@ package org.springframework.web.servlet.support; +import org.springframework.lang.Nullable; import org.springframework.util.ObjectUtils; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; @@ -49,6 +50,7 @@ public abstract class AbstractAnnotationConfigDispatcherServletInitializer * Returns {@code null} if {@link #getRootConfigClasses()} returns {@code null}. */ @Override + @Nullable protected WebApplicationContext createRootApplicationContext() { Class[] configClasses = getRootConfigClasses(); if (!ObjectUtils.isEmpty(configClasses)) { @@ -83,6 +85,7 @@ public abstract class AbstractAnnotationConfigDispatcherServletInitializer * @return the configuration classes for the root application context, or {@code null} * if creation and registration of a root context is not desired */ + @Nullable protected abstract Class[] getRootConfigClasses(); /** @@ -93,6 +96,7 @@ public abstract class AbstractAnnotationConfigDispatcherServletInitializer * @return the configuration classes for the dispatcher servlet application context or * {@code null} if all configuration is specified through root config classes. */ + @Nullable protected abstract Class[] getServletConfigClasses(); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/support/AbstractDispatcherServletInitializer.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/support/AbstractDispatcherServletInitializer.java index 3fe22004ef..1700d95765 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/support/AbstractDispatcherServletInitializer.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/support/AbstractDispatcherServletInitializer.java @@ -17,6 +17,7 @@ package org.springframework.web.servlet.support; import java.util.EnumSet; + import javax.servlet.DispatcherType; import javax.servlet.Filter; import javax.servlet.FilterRegistration; @@ -27,6 +28,7 @@ import javax.servlet.ServletRegistration; import org.springframework.context.ApplicationContextInitializer; import org.springframework.core.Conventions; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; import org.springframework.web.context.AbstractContextLoaderInitializer; @@ -150,6 +152,7 @@ public abstract class AbstractDispatcherServletInitializer extends AbstractConte * @see DispatcherServlet#setContextInitializers * @see #getRootApplicationContextInitializers() */ + @Nullable protected ApplicationContextInitializer[] getServletApplicationContextInitializers() { return null; } @@ -166,6 +169,7 @@ public abstract class AbstractDispatcherServletInitializer extends AbstractConte * @return an array of filters or {@code null} * @see #registerServletFilter(ServletContext, Filter) */ + @Nullable protected Filter[] getServletFilters() { return null; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/support/AbstractFlashMapManager.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/support/AbstractFlashMapManager.java index 0cc4d99ef8..b4a139e24c 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/support/AbstractFlashMapManager.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/support/AbstractFlashMapManager.java @@ -27,6 +27,7 @@ import javax.servlet.http.HttpServletResponse; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.util.MultiValueMap; @@ -143,6 +144,7 @@ public abstract class AbstractFlashMapManager implements FlashMapManager { * Return a FlashMap contained in the given list that matches the request. * @return a matching FlashMap or {@code null} */ + @Nullable private FlashMap getMatchingFlashMap(List allMaps, HttpServletRequest request) { List result = new LinkedList<>(); for (FlashMap flashMap : allMaps) { @@ -241,6 +243,7 @@ public abstract class AbstractFlashMapManager implements FlashMapManager { * @param request the current request * @return a List with FlashMap instances, or {@code null} if none found */ + @Nullable protected abstract List retrieveFlashMaps(HttpServletRequest request); /** @@ -262,6 +265,7 @@ public abstract class AbstractFlashMapManager implements FlashMapManager { * @return the mutex to use (may be {@code null} if none applicable) * @since 4.0.3 */ + @Nullable protected Object getFlashMapsMutex(HttpServletRequest request) { return DEFAULT_FLASH_MAPS_MUTEX; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/support/BindStatus.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/support/BindStatus.java index dd003191e7..9487cbaf0d 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/support/BindStatus.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/support/BindStatus.java @@ -23,6 +23,7 @@ import java.util.List; import org.springframework.beans.BeanWrapper; import org.springframework.beans.PropertyAccessorFactory; import org.springframework.context.NoSuchMessageException; +import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; import org.springframework.validation.BindingResult; import org.springframework.validation.Errors; @@ -199,6 +200,7 @@ public class BindStatus { * Note that the complete bind path as required by the bind tag is * "customer.address.street", if bound to a "customer" bean. */ + @Nullable public String getExpression() { return this.expression; } @@ -209,6 +211,7 @@ public class BindStatus { *

    This value will be an HTML-escaped String if the original value * already was a String. */ + @Nullable public Object getValue() { return this.value; } @@ -218,6 +221,7 @@ public class BindStatus { * '{@code getValue().getClass()}' since '{@code getValue()}' may * return '{@code null}'. */ + @Nullable public Class getValueType() { return this.valueType; } @@ -226,6 +230,7 @@ public class BindStatus { * Return the actual value of the field, i.e. the raw property value, * or {@code null} if not available. */ + @Nullable public Object getActualValue() { return this.actualValue; } @@ -258,6 +263,7 @@ public class BindStatus { * Return the error codes for the field or object, if any. * Returns an empty array instead of null if none. */ + @Nullable public String[] getErrorCodes() { return this.errorCodes; } @@ -303,6 +309,7 @@ public class BindStatus { * @return the current Errors instance, or {@code null} if none * @see org.springframework.validation.BindingResult */ + @Nullable public Errors getErrors() { return this.errors; } @@ -312,6 +319,7 @@ public class BindStatus { * is currently bound to. * @return the current PropertyEditor, or {@code null} if none */ + @Nullable public PropertyEditor getEditor() { return this.editor; } @@ -322,6 +330,7 @@ public class BindStatus { * @param valueClass the value class that an editor is needed for * @return the associated PropertyEditor, or {@code null} if none */ + @Nullable public PropertyEditor findEditor(Class valueClass) { return (this.bindingResult != null ? this.bindingResult.findEditor(this.expression, valueClass) : null); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/support/JspAwareRequestContext.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/support/JspAwareRequestContext.java index 69d5cefe80..4384f6d626 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/support/JspAwareRequestContext.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/support/JspAwareRequestContext.java @@ -18,11 +18,14 @@ package org.springframework.web.servlet.support; import java.util.Locale; import java.util.Map; + import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.jsp.PageContext; import javax.servlet.jsp.jstl.core.Config; +import org.springframework.lang.Nullable; + /** * JSP-aware (and JSTL-aware) subclass of RequestContext, allowing for * population of the context from a {@code javax.servlet.jsp.PageContext}. @@ -55,7 +58,7 @@ public class JspAwareRequestContext extends RequestContext { * @param model the model attributes for the current view * (can be {@code null}, using the request attributes for Errors retrieval) */ - public JspAwareRequestContext(PageContext pageContext, Map model) { + public JspAwareRequestContext(PageContext pageContext, @Nullable Map model) { initContext(pageContext, model); } @@ -66,7 +69,7 @@ public class JspAwareRequestContext extends RequestContext { * @param model the model attributes for the current view * (can be {@code null}, using the request attributes for Errors retrieval) */ - protected void initContext(PageContext pageContext, Map model) { + protected void initContext(PageContext pageContext, @Nullable Map model) { if (!(pageContext.getRequest() instanceof HttpServletRequest)) { throw new IllegalArgumentException("RequestContext only supports HTTP requests"); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/support/JstlUtils.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/support/JstlUtils.java index 959ba68d3a..0a9a8b6d81 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/support/JstlUtils.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/support/JstlUtils.java @@ -19,6 +19,7 @@ package org.springframework.web.servlet.support; import java.util.Locale; import java.util.ResourceBundle; import java.util.TimeZone; + import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; @@ -28,6 +29,7 @@ import javax.servlet.jsp.jstl.fmt.LocalizationContext; import org.springframework.context.MessageSource; import org.springframework.context.support.MessageSourceResourceBundle; import org.springframework.context.support.ResourceBundleMessageSource; +import org.springframework.lang.Nullable; /** * Helper class for preparing JSTL views, @@ -77,7 +79,7 @@ public abstract class JstlUtils { * typically the current ApplicationContext (may be {@code null}) * @see #exposeLocalizationContext(RequestContext) */ - public static void exposeLocalizationContext(HttpServletRequest request, MessageSource messageSource) { + public static void exposeLocalizationContext(HttpServletRequest request, @Nullable MessageSource messageSource) { Locale jstlLocale = RequestContextUtils.getLocale(request); Config.set(request, Config.FMT_LOCALE, jstlLocale); TimeZone timeZone = RequestContextUtils.getTimeZone(request); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/support/RequestContext.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/support/RequestContext.java index a6e7156f5d..67152102e9 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/support/RequestContext.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/support/RequestContext.java @@ -21,6 +21,7 @@ import java.util.List; import java.util.Locale; import java.util.Map; import java.util.TimeZone; + import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -33,6 +34,7 @@ import org.springframework.context.NoSuchMessageException; import org.springframework.context.i18n.LocaleContext; import org.springframework.context.i18n.SimpleTimeZoneAwareLocaleContext; import org.springframework.context.i18n.TimeZoneAwareLocaleContext; +import org.springframework.lang.Nullable; import org.springframework.ui.context.Theme; import org.springframework.ui.context.ThemeSource; import org.springframework.ui.context.support.ResourceBundleThemeSource; @@ -160,7 +162,7 @@ public class RequestContext { * @see org.springframework.web.context.WebApplicationContext * @see org.springframework.web.servlet.DispatcherServlet */ - public RequestContext(HttpServletRequest request, ServletContext servletContext) { + public RequestContext(HttpServletRequest request, @Nullable ServletContext servletContext) { initContext(request, null, servletContext, null); } @@ -175,7 +177,7 @@ public class RequestContext { * @see org.springframework.web.servlet.DispatcherServlet * @see #RequestContext(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, javax.servlet.ServletContext, Map) */ - public RequestContext(HttpServletRequest request, Map model) { + public RequestContext(HttpServletRequest request, @Nullable Map model) { initContext(request, null, null, model); } @@ -193,8 +195,8 @@ public class RequestContext { * @see org.springframework.web.context.WebApplicationContext * @see org.springframework.web.servlet.DispatcherServlet */ - public RequestContext(HttpServletRequest request, HttpServletResponse response, ServletContext servletContext, - Map model) { + public RequestContext(HttpServletRequest request, HttpServletResponse response, @Nullable ServletContext servletContext, + @Nullable Map model) { initContext(request, response, servletContext, model); } @@ -220,8 +222,8 @@ public class RequestContext { * @see org.springframework.web.servlet.DispatcherServlet#LOCALE_RESOLVER_ATTRIBUTE * @see org.springframework.web.servlet.DispatcherServlet#THEME_RESOLVER_ATTRIBUTE */ - protected void initContext(HttpServletRequest request, HttpServletResponse response, ServletContext servletContext, - Map model) { + protected void initContext(HttpServletRequest request, HttpServletResponse response, @Nullable ServletContext servletContext, + @Nullable Map model) { this.request = request; this.response = response; @@ -299,6 +301,7 @@ public class RequestContext { * session or application scope; returns {@code null} if not found. * @return the fallback time zone (or {@code null} if none derivable from the request) */ + @Nullable protected TimeZone getFallbackTimeZone() { if (jstlPresent) { TimeZone timeZone = JstlLocaleResolver.getJstlTimeZone(getRequest(), getServletContext()); @@ -314,6 +317,7 @@ public class RequestContext { *

    The default implementation returns the default theme (with name "theme"). * @return the fallback theme (never {@code null}) */ + @Nullable protected Theme getFallbackTheme() { ThemeSource themeSource = RequestContextUtils.getThemeSource(getRequest()); if (themeSource == null) { @@ -359,6 +363,7 @@ public class RequestContext { * Return the model Map that this RequestContext encapsulates, if any. * @return the populated model Map, or {@code null} if none available */ + @Nullable public final Map getModel() { return this.model; } @@ -379,6 +384,7 @@ public class RequestContext { * Also includes a fallback check for JSTL's TimeZone attribute. * @see RequestContextUtils#getTimeZone */ + @Nullable public TimeZone getTimeZone() { return this.timeZone; } @@ -534,6 +540,7 @@ public class RequestContext { * WebApplicationContext under the name {@code "requestDataValueProcessor"}. * Or {@code null} if no matching bean was found. */ + @Nullable public RequestDataValueProcessor getRequestDataValueProcessor() { return this.requestDataValueProcessor; } @@ -639,7 +646,7 @@ public class RequestContext { * @param defaultMessage String to return if the lookup fails * @return the message */ - public String getMessage(String code, Object[] args, String defaultMessage) { + public String getMessage(String code, @Nullable Object[] args, String defaultMessage) { return getMessage(code, args, defaultMessage, isDefaultHtmlEscape()); } @@ -650,7 +657,7 @@ public class RequestContext { * @param defaultMessage String to return if the lookup fails * @return the message */ - public String getMessage(String code, List args, String defaultMessage) { + public String getMessage(String code, @Nullable List args, String defaultMessage) { return getMessage(code, (args != null ? args.toArray() : null), defaultMessage, isDefaultHtmlEscape()); } @@ -662,7 +669,7 @@ public class RequestContext { * @param htmlEscape HTML escape the message? * @return the message */ - public String getMessage(String code, Object[] args, String defaultMessage, boolean htmlEscape) { + public String getMessage(String code, @Nullable Object[] args, String defaultMessage, boolean htmlEscape) { String msg = this.webApplicationContext.getMessage(code, args, defaultMessage, this.locale); return (htmlEscape ? HtmlUtils.htmlEscape(msg) : msg); } @@ -684,7 +691,7 @@ public class RequestContext { * @return the message * @throws org.springframework.context.NoSuchMessageException if not found */ - public String getMessage(String code, Object[] args) throws NoSuchMessageException { + public String getMessage(String code, @Nullable Object[] args) throws NoSuchMessageException { return getMessage(code, args, isDefaultHtmlEscape()); } @@ -695,7 +702,7 @@ public class RequestContext { * @return the message * @throws org.springframework.context.NoSuchMessageException if not found */ - public String getMessage(String code, List args) throws NoSuchMessageException { + public String getMessage(String code, @Nullable List args) throws NoSuchMessageException { return getMessage(code, (args != null ? args.toArray() : null), isDefaultHtmlEscape()); } @@ -707,7 +714,7 @@ public class RequestContext { * @return the message * @throws org.springframework.context.NoSuchMessageException if not found */ - public String getMessage(String code, Object[] args, boolean htmlEscape) throws NoSuchMessageException { + public String getMessage(String code, @Nullable Object[] args, boolean htmlEscape) throws NoSuchMessageException { String msg = this.webApplicationContext.getMessage(code, args, this.locale); return (htmlEscape ? HtmlUtils.htmlEscape(msg) : msg); } @@ -755,7 +762,7 @@ public class RequestContext { * @param defaultMessage String to return if the lookup fails * @return the message */ - public String getThemeMessage(String code, Object[] args, String defaultMessage) { + public String getThemeMessage(String code, @Nullable Object[] args, String defaultMessage) { return getTheme().getMessageSource().getMessage(code, args, defaultMessage, this.locale); } @@ -768,7 +775,7 @@ public class RequestContext { * @param defaultMessage String to return if the lookup fails * @return the message */ - public String getThemeMessage(String code, List args, String defaultMessage) { + public String getThemeMessage(String code, @Nullable List args, String defaultMessage) { return getTheme().getMessageSource().getMessage(code, (args != null ? args.toArray() : null), defaultMessage, this.locale); } @@ -794,7 +801,7 @@ public class RequestContext { * @return the message * @throws org.springframework.context.NoSuchMessageException if not found */ - public String getThemeMessage(String code, Object[] args) throws NoSuchMessageException { + public String getThemeMessage(String code, @Nullable Object[] args) throws NoSuchMessageException { return getTheme().getMessageSource().getMessage(code, args, this.locale); } @@ -807,7 +814,7 @@ public class RequestContext { * @return the message * @throws org.springframework.context.NoSuchMessageException if not found */ - public String getThemeMessage(String code, List args) throws NoSuchMessageException { + public String getThemeMessage(String code, @Nullable List args) throws NoSuchMessageException { return getTheme().getMessageSource().getMessage(code, (args != null ? args.toArray() : null), this.locale); } @@ -828,6 +835,7 @@ public class RequestContext { * @param name name of the bind object * @return the Errors instance, or {@code null} if not found */ + @Nullable public Errors getErrors(String name) { return getErrors(name, isDefaultHtmlEscape()); } @@ -838,6 +846,7 @@ public class RequestContext { * @param htmlEscape create an Errors instance with automatic HTML escaping? * @return the Errors instance, or {@code null} if not found */ + @Nullable public Errors getErrors(String name, boolean htmlEscape) { if (this.errorsMap == null) { this.errorsMap = new HashMap<>(); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/support/RequestContextUtils.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/support/RequestContextUtils.java index c9c7590f88..f97f8b0a5b 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/support/RequestContextUtils.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/support/RequestContextUtils.java @@ -19,6 +19,7 @@ package org.springframework.web.servlet.support; import java.util.Locale; import java.util.Map; import java.util.TimeZone; + import javax.servlet.ServletContext; import javax.servlet.ServletRequest; import javax.servlet.http.HttpServletRequest; @@ -26,6 +27,7 @@ import javax.servlet.http.HttpServletResponse; import org.springframework.context.i18n.LocaleContext; import org.springframework.context.i18n.TimeZoneAwareLocaleContext; +import org.springframework.lang.Nullable; import org.springframework.ui.context.Theme; import org.springframework.ui.context.ThemeSource; import org.springframework.util.Assert; @@ -81,6 +83,7 @@ public abstract class RequestContextUtils { * @see WebApplicationContextUtils#getWebApplicationContext(ServletContext) * @see ContextLoader#getCurrentWebApplicationContext() */ + @Nullable public static WebApplicationContext findWebApplicationContext( HttpServletRequest request, ServletContext servletContext) { @@ -112,6 +115,7 @@ public abstract class RequestContextUtils { * @see ServletRequest#getServletContext() * @see ContextLoader#getCurrentWebApplicationContext() */ + @Nullable public static WebApplicationContext findWebApplicationContext(HttpServletRequest request) { return findWebApplicationContext(request, request.getServletContext()); } @@ -122,6 +126,7 @@ public abstract class RequestContextUtils { * @param request current HTTP request * @return the current LocaleResolver, or {@code null} if not found */ + @Nullable public static LocaleResolver getLocaleResolver(HttpServletRequest request) { return (LocaleResolver) request.getAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE); } @@ -163,6 +168,7 @@ public abstract class RequestContextUtils { * @see #getLocaleResolver * @see org.springframework.context.i18n.LocaleContextHolder#getTimeZone() */ + @Nullable public static TimeZone getTimeZone(HttpServletRequest request) { LocaleResolver localeResolver = getLocaleResolver(request); if (localeResolver instanceof LocaleContextResolver) { @@ -180,6 +186,7 @@ public abstract class RequestContextUtils { * @param request current HTTP request * @return the current ThemeResolver, or {@code null} if not found */ + @Nullable public static ThemeResolver getThemeResolver(HttpServletRequest request) { return (ThemeResolver) request.getAttribute(DispatcherServlet.THEME_RESOLVER_ATTRIBUTE); } @@ -201,6 +208,7 @@ public abstract class RequestContextUtils { * @return the current theme, or {@code null} if not found * @see #getThemeResolver */ + @Nullable public static Theme getTheme(HttpServletRequest request) { ThemeResolver themeResolver = getThemeResolver(request); ThemeSource themeSource = getThemeSource(request); @@ -220,6 +228,7 @@ public abstract class RequestContextUtils { * @see FlashMap */ @SuppressWarnings("unchecked") + @Nullable public static Map getInputFlashMap(HttpServletRequest request) { return (Map) request.getAttribute(DispatcherServlet.INPUT_FLASH_MAP_ATTRIBUTE); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/support/RequestDataValueProcessor.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/support/RequestDataValueProcessor.java index d78c80015f..967db3b9aa 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/support/RequestDataValueProcessor.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/support/RequestDataValueProcessor.java @@ -17,8 +17,11 @@ package org.springframework.web.servlet.support; import java.util.Map; + import javax.servlet.http.HttpServletRequest; +import org.springframework.lang.Nullable; + /** * A contract for inspecting and potentially modifying request data values such * as URL query parameters or form field values before they are rendered by a @@ -61,6 +64,7 @@ public interface RequestDataValueProcessor { * @param request the current request * @return additional hidden form fields to be added, or {@code null} */ + @Nullable Map getExtraHiddenFields(HttpServletRequest request); /** diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/support/ServletUriComponentsBuilder.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/support/ServletUriComponentsBuilder.java index f39c12a45b..8cc802ba4f 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/support/ServletUriComponentsBuilder.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/support/ServletUriComponentsBuilder.java @@ -17,10 +17,12 @@ package org.springframework.web.servlet.support; import java.util.Enumeration; + import javax.servlet.http.HttpServletRequest; import org.springframework.http.HttpRequest; import org.springframework.http.server.ServletServerHttpRequest; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.StringUtils; import org.springframework.web.context.request.RequestAttributes; @@ -212,6 +214,7 @@ public class ServletUriComponentsBuilder extends UriComponentsBuilder { * @return the removed path extension for possible re-use, or {@code null} * @since 4.0 */ + @Nullable public String removePathExtension() { String extension = null; if (this.originalPath != null) { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/support/package-info.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/support/package-info.java index 66deafef01..ac384bde84 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/support/package-info.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/support/package-info.java @@ -3,4 +3,7 @@ * Provides easy evaluation of the request context in views, * and miscellaneous HandlerInterceptor implementations. */ +@NonNullApi package org.springframework.web.servlet.support; + +import org.springframework.lang.NonNullApi; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/BindTag.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/BindTag.java index e773e2a29f..5481cc53e3 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/BindTag.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/BindTag.java @@ -17,9 +17,11 @@ package org.springframework.web.servlet.tags; import java.beans.PropertyEditor; + import javax.servlet.jsp.JspTagException; import javax.servlet.jsp.PageContext; +import org.springframework.lang.Nullable; import org.springframework.validation.Errors; import org.springframework.web.servlet.support.BindStatus; @@ -155,6 +157,7 @@ public class BindTag extends HtmlEscapingAwareTag implements EditorAwareTag { * @return the property that this tag is currently bound to, * or {@code null} if none */ + @Nullable public final String getProperty() { return this.status.getExpression(); } @@ -164,6 +167,7 @@ public class BindTag extends HtmlEscapingAwareTag implements EditorAwareTag { * Intended for cooperating nesting tags. * @return the current Errors instance, or {@code null} if none */ + @Nullable public final Errors getErrors() { return this.status.getErrors(); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/EditorAwareTag.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/EditorAwareTag.java index 384e75f6dc..a5dc589e70 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/EditorAwareTag.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/EditorAwareTag.java @@ -17,8 +17,11 @@ package org.springframework.web.servlet.tags; import java.beans.PropertyEditor; + import javax.servlet.jsp.JspException; +import org.springframework.lang.Nullable; + /** * Interface to be implemented by JSP tags that expose a * PropertyEditor for a property that they are currently bound to. @@ -36,6 +39,7 @@ public interface EditorAwareTag { * @return the current PropertyEditor, or {@code null} if none * @throws JspException if resolving the editor failed */ + @Nullable PropertyEditor getEditor() throws JspException; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/MessageTag.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/MessageTag.java index eb1bbba3b0..703bba3019 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/MessageTag.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/MessageTag.java @@ -26,6 +26,7 @@ import javax.servlet.jsp.JspTagException; import org.springframework.context.MessageSource; import org.springframework.context.MessageSourceResolvable; import org.springframework.context.NoSuchMessageException; +import org.springframework.lang.Nullable; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; import org.springframework.web.util.JavaScriptUtils; @@ -264,6 +265,7 @@ public class MessageTag extends HtmlEscapingAwareTag implements ArgumentAware { * @throws JspException if argument conversion failed * @see #setArguments */ + @Nullable protected Object[] resolveArguments(Object arguments) throws JspException { if (arguments instanceof String) { String[] stringArray = diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/AbstractDataBoundFormElementTag.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/AbstractDataBoundFormElementTag.java index 8a9b82528c..682d791518 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/AbstractDataBoundFormElementTag.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/AbstractDataBoundFormElementTag.java @@ -17,12 +17,14 @@ package org.springframework.web.servlet.tags.form; import java.beans.PropertyEditor; + import javax.servlet.ServletRequest; import javax.servlet.http.HttpServletRequest; import javax.servlet.jsp.JspException; import javax.servlet.jsp.PageContext; import org.springframework.beans.PropertyAccessor; +import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; import org.springframework.web.servlet.support.BindStatus; import org.springframework.web.servlet.support.RequestDataValueProcessor; @@ -123,6 +125,7 @@ public abstract class AbstractDataBoundFormElementTag extends AbstractFormTag im * @see #getId() * @see #autogenerateId() */ + @Nullable protected String resolveId() throws JspException { Object id = evaluate("id", getId()); if (id != null) { @@ -137,6 +140,7 @@ public abstract class AbstractDataBoundFormElementTag extends AbstractFormTag im *

    The default implementation simply delegates to {@link #getName()}, * deleting invalid characters (such as "[" or "]"). */ + @Nullable protected String autogenerateId() throws JspException { return StringUtils.deleteAny(getName(), "[]"); } @@ -150,6 +154,7 @@ public abstract class AbstractDataBoundFormElementTag extends AbstractFormTag im * the value of the '{@code name}' attribute without changing the bind path. * @return the value for the HTML '{@code name}' attribute */ + @Nullable protected String getName() throws JspException { return getPropertyPath(); } @@ -200,6 +205,7 @@ public abstract class AbstractDataBoundFormElementTag extends AbstractFormTag im /** * Get the {@link PropertyEditor}, if any, in use for value bound to this tag. */ + @Nullable protected PropertyEditor getPropertyEditor() throws JspException { return getBindStatus().getEditor(); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/AbstractFormTag.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/AbstractFormTag.java index 8227f35353..1fbc7e64f4 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/AbstractFormTag.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/AbstractFormTag.java @@ -17,8 +17,10 @@ package org.springframework.web.servlet.tags.form; import java.beans.PropertyEditor; + import javax.servlet.jsp.JspException; +import org.springframework.lang.Nullable; import org.springframework.util.ObjectUtils; import org.springframework.web.servlet.tags.HtmlEscapingAwareTag; @@ -56,7 +58,7 @@ public abstract class AbstractFormTag extends HtmlEscapingAwareTag { * or empty, no attribute is written. * @see TagWriter#writeOptionalAttributeValue(String, String) */ - protected final void writeOptionalAttribute(TagWriter tagWriter, String attributeName, String value) + protected final void writeOptionalAttribute(TagWriter tagWriter, String attributeName, @Nullable String value) throws JspException { if (value != null) { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/ErrorsTag.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/ErrorsTag.java index a55e203acf..054011d7db 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/ErrorsTag.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/ErrorsTag.java @@ -19,6 +19,7 @@ package org.springframework.web.servlet.tags.form; import java.util.ArrayList; import java.util.Arrays; import java.util.List; + import javax.servlet.jsp.JspException; import javax.servlet.jsp.PageContext; import javax.servlet.jsp.tagext.BodyTag; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/TagWriter.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/TagWriter.java index 0f723d1a48..f4b83ccf64 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/TagWriter.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/TagWriter.java @@ -19,9 +19,11 @@ package org.springframework.web.servlet.tags.form; import java.io.IOException; import java.io.Writer; import java.util.Stack; + import javax.servlet.jsp.JspException; import javax.servlet.jsp.PageContext; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -100,7 +102,7 @@ public class TagWriter { * or zero length. * @see #writeAttribute(String, String) */ - public void writeOptionalAttributeValue(String attributeName, String attributeValue) throws JspException { + public void writeOptionalAttributeValue(String attributeName, @Nullable String attributeValue) throws JspException { if (StringUtils.hasText(attributeValue)) { writeAttribute(attributeName, attributeValue); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/package-info.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/package-info.java index e132e7070e..467feafe30 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/package-info.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/package-info.java @@ -3,4 +3,7 @@ * Supports JSP view implementations within Spring's web MVC framework. * See {@code spring.tld} for descriptions of the various tags. */ +@NonNullApi package org.springframework.web.servlet.tags; + +import org.springframework.lang.NonNullApi; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/theme/package-info.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/theme/package-info.java index d3f409797b..b4ff12b15d 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/theme/package-info.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/theme/package-info.java @@ -17,4 +17,7 @@ *

  • The {@code pagedlist} demo application uses themes
  • * */ +@NonNullApi package org.springframework.web.servlet.theme; + +import org.springframework.lang.NonNullApi; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/AbstractCachingViewResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/AbstractCachingViewResolver.java index a9653bb323..52e69919db 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/AbstractCachingViewResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/AbstractCachingViewResolver.java @@ -20,9 +20,11 @@ import java.util.LinkedHashMap; import java.util.Locale; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; + import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.springframework.lang.Nullable; import org.springframework.web.context.support.WebApplicationObjectSupport; import org.springframework.web.servlet.View; import org.springframework.web.servlet.ViewResolver; @@ -240,6 +242,7 @@ public abstract class AbstractCachingViewResolver extends WebApplicationObjectSu * @throws Exception if the view couldn't be resolved * @see #loadView */ + @Nullable protected View createView(String viewName, Locale locale) throws Exception { return loadView(viewName, locale); } @@ -257,6 +260,7 @@ public abstract class AbstractCachingViewResolver extends WebApplicationObjectSu * @throws Exception if the view couldn't be resolved * @see #resolveViewName */ + @Nullable protected abstract View loadView(String viewName, Locale locale) throws Exception; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/AbstractView.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/AbstractView.java index e746c5f5b0..9733c6c169 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/AbstractView.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/AbstractView.java @@ -32,6 +32,7 @@ import javax.servlet.http.HttpServletResponse; import org.springframework.beans.factory.BeanNameAware; import org.springframework.http.MediaType; +import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; import org.springframework.web.context.support.ContextExposingHttpServletRequest; import org.springframework.web.context.support.WebApplicationObjectSupport; @@ -127,6 +128,7 @@ public abstract class AbstractView extends WebApplicationObjectSupport implement /** * Return the name of the RequestContext attribute, if any. */ + @Nullable public String getRequestContextAttribute() { return this.requestContextAttribute; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/ContentNegotiatingViewResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/ContentNegotiatingViewResolver.java index 71a47d3b5e..1ba64f6ea2 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/ContentNegotiatingViewResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/ContentNegotiatingViewResolver.java @@ -33,6 +33,7 @@ import org.springframework.beans.factory.InitializingBean; import org.springframework.core.Ordered; import org.springframework.core.annotation.AnnotationAwareOrderComparator; import org.springframework.http.MediaType; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; @@ -240,6 +241,7 @@ public class ContentNegotiatingViewResolver extends WebApplicationObjectSupport * @param request the current servlet request * @return the list of media types requested, if any */ + @Nullable protected List getMediaTypes(HttpServletRequest request) { try { ServletWebRequest webRequest = new ServletWebRequest(request); @@ -317,6 +319,7 @@ public class ContentNegotiatingViewResolver extends WebApplicationObjectSupport return candidateViews; } + @Nullable private View getBestView(List candidateViews, List requestedMediaTypes, RequestAttributes attrs) { for (View candidateView : candidateViews) { if (candidateView instanceof SmartView) { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/UrlBasedViewResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/UrlBasedViewResolver.java index 5d126856fd..9c25542793 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/UrlBasedViewResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/UrlBasedViewResolver.java @@ -20,10 +20,12 @@ import java.util.HashMap; import java.util.Locale; import java.util.Map; import java.util.Properties; + import javax.servlet.http.HttpServletResponse; import org.springframework.beans.BeanUtils; import org.springframework.core.Ordered; +import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; import org.springframework.util.PatternMatchUtils; import org.springframework.web.servlet.View; @@ -200,6 +202,7 @@ public class UrlBasedViewResolver extends AbstractCachingViewResolver implements /** * Return the content type for all views, if any. */ + @Nullable protected String getContentType() { return this.contentType; } @@ -288,6 +291,7 @@ public class UrlBasedViewResolver extends AbstractCachingViewResolver implements /** * Return the name of the RequestContext attribute for all views, if any. */ + @Nullable protected String getRequestContextAttribute() { return this.requestContextAttribute; } @@ -343,7 +347,7 @@ public class UrlBasedViewResolver extends AbstractCachingViewResolver implements *
      * @see AbstractView#setExposePathVariables */ - public void setExposePathVariables(Boolean exposePathVariables) { + public void setExposePathVariables(@Nullable Boolean exposePathVariables) { this.exposePathVariables = exposePathVariables; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/document/package-info.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/document/package-info.java index 7e4a4b40dc..c074a1f04b 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/document/package-info.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/document/package-info.java @@ -2,4 +2,7 @@ * Support classes for document generation, * providing View implementations for PDF and Excel. */ +@NonNullApi package org.springframework.web.servlet.view.document; + +import org.springframework.lang.NonNullApi; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/feed/package-info.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/feed/package-info.java index 802c2e9afd..6ac449575f 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/feed/package-info.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/feed/package-info.java @@ -2,4 +2,7 @@ * Support classes for feed generation, providing View implementations for Atom and RSS. * Based on the ROME tools project. */ +@NonNullApi package org.springframework.web.servlet.view.feed; + +import org.springframework.lang.NonNullApi; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/freemarker/FreeMarkerView.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/freemarker/FreeMarkerView.java index 0b6cc3dc04..0558b942db 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/freemarker/FreeMarkerView.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/freemarker/FreeMarkerView.java @@ -52,6 +52,7 @@ import org.springframework.beans.factory.BeanFactoryUtils; import org.springframework.beans.factory.BeanInitializationException; import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.context.ApplicationContextException; +import org.springframework.lang.Nullable; import org.springframework.web.servlet.support.RequestContextUtils; import org.springframework.web.servlet.view.AbstractTemplateView; @@ -399,6 +400,7 @@ public class FreeMarkerView extends AbstractTemplateView { } @Override + @Nullable public String getInitParameter(String paramName) { return null; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/freemarker/package-info.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/freemarker/package-info.java index 415eef0b20..e7cfa6f28a 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/freemarker/package-info.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/freemarker/package-info.java @@ -4,4 +4,7 @@ * as Spring web view technology. * Contains a View implementation for FreeMarker templates. */ +@NonNullApi package org.springframework.web.servlet.view.freemarker; + +import org.springframework.lang.NonNullApi; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/groovy/package-info.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/groovy/package-info.java index 74a6188dde..48600573de 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/groovy/package-info.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/groovy/package-info.java @@ -4,4 +4,7 @@ * Groovy Templates as Spring web view technology. * Contains a View implementation for Groovy templates. */ +@NonNullApi package org.springframework.web.servlet.view.groovy; + +import org.springframework.lang.NonNullApi; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/json/MappingJackson2JsonView.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/json/MappingJackson2JsonView.java index b365d2c8f7..7656cdd1c0 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/json/MappingJackson2JsonView.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/json/MappingJackson2JsonView.java @@ -34,6 +34,7 @@ import com.fasterxml.jackson.databind.ser.FilterProvider; import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; import org.springframework.http.converter.json.MappingJacksonValue; +import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; import org.springframework.validation.BindingResult; @@ -173,6 +174,7 @@ public class MappingJackson2JsonView extends AbstractJackson2View { this.jsonpParameterNames = jsonpParameterNames; } + @Nullable private String getJsonpParameterValue(HttpServletRequest request) { if (this.jsonpParameterNames != null) { for (String name : this.jsonpParameterNames) { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/json/package-info.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/json/package-info.java index 53c24b52e2..f3a8077e50 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/json/package-info.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/json/package-info.java @@ -1,4 +1,7 @@ /** * Support classes for providing a View implementation based on JSON serialization. */ +@NonNullApi package org.springframework.web.servlet.view.json; + +import org.springframework.lang.NonNullApi; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/package-info.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/package-info.java index 9dd27b5879..63a3bb554d 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/package-info.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/package-info.java @@ -8,4 +8,7 @@ * by subclassing the AbstractView class in this package can be * very helpful if an application has unusual view requirements. */ +@NonNullApi package org.springframework.web.servlet.view; + +import org.springframework.lang.NonNullApi; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/script/ScriptTemplateView.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/script/ScriptTemplateView.java index 823f17b3f3..f9d4ab0b0e 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/script/ScriptTemplateView.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/script/ScriptTemplateView.java @@ -41,6 +41,7 @@ import org.springframework.context.ApplicationContextException; import org.springframework.core.NamedThreadLocal; import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceLoader; +import org.springframework.lang.Nullable; import org.springframework.scripting.support.StandardScriptEvalException; import org.springframework.scripting.support.StandardScriptUtils; import org.springframework.util.Assert; @@ -311,6 +312,7 @@ public class ScriptTemplateView extends AbstractUrlBasedView { } } + @Nullable protected Resource getResource(String location) { for (String path : this.resourceLoaderPaths) { Resource resource = this.resourceLoader.getResource(path + location); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/script/package-info.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/script/package-info.java index 141d353730..4d01c8d4ce 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/script/package-info.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/script/package-info.java @@ -3,4 +3,7 @@ * (as included in Java 6+), e.g. using JavaScript via Nashorn on JDK 8. * Contains a View implementation for scripted templates. */ +@NonNullApi package org.springframework.web.servlet.view.script; + +import org.springframework.lang.NonNullApi; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/tiles3/package-info.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/tiles3/package-info.java index 8934e376a9..9905c3fe0a 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/tiles3/package-info.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/tiles3/package-info.java @@ -4,4 +4,7 @@ * (the standalone version of Tiles) as Spring web view technology. * Contains a View implementation for Tiles definitions. */ +@NonNullApi package org.springframework.web.servlet.view.tiles3; + +import org.springframework.lang.NonNullApi; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/xml/MarshallingView.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/xml/MarshallingView.java index 582807358b..a39cd13b41 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/xml/MarshallingView.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/xml/MarshallingView.java @@ -18,11 +18,13 @@ package org.springframework.web.servlet.view.xml; import java.io.ByteArrayOutputStream; import java.util.Map; + import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.xml.bind.JAXBElement; import javax.xml.transform.stream.StreamResult; +import org.springframework.lang.Nullable; import org.springframework.oxm.Marshaller; import org.springframework.util.Assert; import org.springframework.validation.BindingResult; @@ -123,6 +125,7 @@ public class MarshallingView extends AbstractView { * {@linkplain #setModelKey(String) model key} is not supported by the marshaller * @see #setModelKey(String) */ + @Nullable protected Object locateToBeMarshalled(Map model) throws IllegalStateException { if (this.modelKey != null) { Object value = model.get(this.modelKey); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/xml/package-info.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/xml/package-info.java index d6cb9c7f3d..fe2e028126 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/xml/package-info.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/xml/package-info.java @@ -1,4 +1,7 @@ /** * Support classes for providing a View implementation based on XML Marshalling. */ +@NonNullApi package org.springframework.web.servlet.view.xml; + +import org.springframework.lang.NonNullApi; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/xslt/XsltView.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/xslt/XsltView.java index 0cf770d4b6..5bf371aa4d 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/xslt/XsltView.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/xslt/XsltView.java @@ -22,6 +22,7 @@ import java.io.Reader; import java.util.Enumeration; import java.util.Map; import java.util.Properties; + import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.xml.transform.ErrorListener; @@ -44,6 +45,7 @@ import org.w3c.dom.Node; import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContextException; import org.springframework.core.io.Resource; +import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; import org.springframework.util.ReflectionUtils; import org.springframework.util.StringUtils; @@ -194,7 +196,7 @@ public class XsltView extends AbstractUrlBasedView { * @see #setTransformerFactoryClass * @see #getTransformerFactory() */ - protected TransformerFactory newTransformerFactory(Class transformerFactoryClass) { + protected TransformerFactory newTransformerFactory(@Nullable Class transformerFactoryClass) { if (transformerFactoryClass != null) { try { return ReflectionUtils.accessibleConstructor(transformerFactoryClass).newInstance(); @@ -267,6 +269,7 @@ public class XsltView extends AbstractUrlBasedView { * @see #setSourceKey * @see #convertSource */ + @Nullable protected Source locateSource(Map model) throws Exception { if (this.sourceKey != null) { return convertSource(model.get(this.sourceKey)); @@ -468,7 +471,7 @@ public class XsltView extends AbstractUrlBasedView { *

      Only works for {@link StreamSource StreamSources}. * @param source the XSLT Source to close (may be {@code null}) */ - private void closeSourceIfNecessary(Source source) { + private void closeSourceIfNecessary(@Nullable Source source) { if (source instanceof StreamSource) { StreamSource streamSource = (StreamSource) source; if (streamSource.getReader() != null) { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/xslt/package-info.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/xslt/package-info.java index 4203e0f989..aad6d77083 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/xslt/package-info.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/xslt/package-info.java @@ -2,4 +2,7 @@ * Support classes for XSLT, * providing a View implementation for XSLT stylesheets. */ +@NonNullApi package org.springframework.web.servlet.view.xslt; + +import org.springframework.lang.NonNullApi; diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/CloseStatus.java b/spring-websocket/src/main/java/org/springframework/web/socket/CloseStatus.java index c34307370e..ba380390fb 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/CloseStatus.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/CloseStatus.java @@ -16,6 +16,7 @@ package org.springframework.web.socket; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; @@ -177,6 +178,7 @@ public final class CloseStatus { /** * Return the reason, or {@code null} if none. */ + @Nullable public String getReason() { return this.reason; } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/WebSocketSession.java b/spring-websocket/src/main/java/org/springframework/web/socket/WebSocketSession.java index d212b9596b..cad0cef7fc 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/WebSocketSession.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/WebSocketSession.java @@ -25,6 +25,7 @@ import java.util.List; import java.util.Map; import org.springframework.http.HttpHeaders; +import org.springframework.lang.Nullable; /** * A WebSocket session abstraction. Allows sending messages over a WebSocket @@ -71,6 +72,7 @@ public interface WebSocketSession extends Closeable { /** * Return the address on which the request was received. */ + @Nullable InetSocketAddress getLocalAddress(); /** @@ -83,6 +85,7 @@ public interface WebSocketSession extends Closeable { * @return the protocol identifier, or {@code null} if no protocol * was specified or negotiated successfully */ + @Nullable String getAcceptedProtocol(); /** diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/adapter/NativeWebSocketSession.java b/spring-websocket/src/main/java/org/springframework/web/socket/adapter/NativeWebSocketSession.java index ef70327912..b0098f01c6 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/adapter/NativeWebSocketSession.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/adapter/NativeWebSocketSession.java @@ -16,6 +16,7 @@ package org.springframework.web.socket.adapter; +import org.springframework.lang.Nullable; import org.springframework.web.socket.WebSocketSession; /** @@ -31,6 +32,7 @@ public interface NativeWebSocketSession extends WebSocketSession { * Return the underlying native WebSocketSession, if available. * @return the native session or {@code null} */ + @Nullable Object getNativeSession(); /** @@ -38,6 +40,7 @@ public interface NativeWebSocketSession extends WebSocketSession { * @param requiredType the required type of the session * @return the native session of the required type or {@code null} */ + @Nullable T getNativeSession(Class requiredType); } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/adapter/jetty/JettyWebSocketSession.java b/spring-websocket/src/main/java/org/springframework/web/socket/adapter/jetty/JettyWebSocketSession.java index f36ebe5bac..6d70c7e83b 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/adapter/jetty/JettyWebSocketSession.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/adapter/jetty/JettyWebSocketSession.java @@ -31,6 +31,7 @@ import org.eclipse.jetty.websocket.api.WebSocketException; import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig; import org.springframework.http.HttpHeaders; +import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; import org.springframework.util.ObjectUtils; import org.springframework.web.socket.BinaryMessage; @@ -81,7 +82,7 @@ public class JettyWebSocketSession extends AbstractWebSocketSession { * @param user the user associated with the session; if {@code null} we'll fallback on the * user available via {@link org.eclipse.jetty.websocket.api.Session#getUpgradeRequest()} */ - public JettyWebSocketSession(Map attributes, Principal user) { + public JettyWebSocketSession(Map attributes, @Nullable Principal user) { super(attributes); this.user = user; } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/adapter/jetty/package-info.java b/spring-websocket/src/main/java/org/springframework/web/socket/adapter/jetty/package-info.java index bd8564d657..8d4d0c71b9 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/adapter/jetty/package-info.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/adapter/jetty/package-info.java @@ -1,4 +1,7 @@ /** * Adapter classes for the Jetty WebSocket API. */ +@NonNullApi package org.springframework.web.socket.adapter.jetty; + +import org.springframework.lang.NonNullApi; diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/adapter/package-info.java b/spring-websocket/src/main/java/org/springframework/web/socket/adapter/package-info.java index 338750e1ef..b049cd8005 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/adapter/package-info.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/adapter/package-info.java @@ -1,4 +1,7 @@ /** * Classes adapting Spring's WebSocket API to and from WebSocket providers. */ +@NonNullApi package org.springframework.web.socket.adapter; + +import org.springframework.lang.NonNullApi; diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/adapter/standard/ConvertingEncoderDecoderSupport.java b/spring-websocket/src/main/java/org/springframework/web/socket/adapter/standard/ConvertingEncoderDecoderSupport.java index 76aeb7cad8..6b2cc7bbe5 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/adapter/standard/ConvertingEncoderDecoderSupport.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/adapter/standard/ConvertingEncoderDecoderSupport.java @@ -17,6 +17,7 @@ package org.springframework.web.socket.adapter.standard; import java.nio.ByteBuffer; + import javax.websocket.DecodeException; import javax.websocket.Decoder; import javax.websocket.EncodeException; @@ -32,6 +33,7 @@ import org.springframework.core.GenericTypeResolver; import org.springframework.core.convert.ConversionException; import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.TypeDescriptor; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.context.ContextLoader; @@ -122,6 +124,7 @@ public abstract class ConvertingEncoderDecoderSupport { * not using {@link ContextLoader}, this method should be overridden. * @return the {@link ApplicationContext} or {@code null} */ + @Nullable protected ApplicationContext getApplicationContext() { return ContextLoader.getCurrentWebApplicationContext(); } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/adapter/standard/StandardWebSocketSession.java b/spring-websocket/src/main/java/org/springframework/web/socket/adapter/standard/StandardWebSocketSession.java index 84a8228c6b..06f6452f3d 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/adapter/standard/StandardWebSocketSession.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/adapter/standard/StandardWebSocketSession.java @@ -24,12 +24,14 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; + import javax.websocket.CloseReason; import javax.websocket.CloseReason.CloseCodes; import javax.websocket.Extension; import javax.websocket.Session; import org.springframework.http.HttpHeaders; +import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; import org.springframework.web.socket.BinaryMessage; import org.springframework.web.socket.CloseStatus; @@ -89,7 +91,7 @@ public class StandardWebSocketSession extends AbstractWebSocketSession * fallback on the user available in the underlying WebSocket session */ public StandardWebSocketSession(HttpHeaders headers, Map attributes, - InetSocketAddress localAddress, InetSocketAddress remoteAddress, Principal user) { + InetSocketAddress localAddress, InetSocketAddress remoteAddress, @Nullable Principal user) { super(attributes); headers = (headers != null) ? headers : new HttpHeaders(); diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/adapter/standard/package-info.java b/spring-websocket/src/main/java/org/springframework/web/socket/adapter/standard/package-info.java index b8c121ae86..752d7f9b5a 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/adapter/standard/package-info.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/adapter/standard/package-info.java @@ -1,4 +1,7 @@ /** * Adapter classes for the standard Java WebSocket API. */ +@NonNullApi package org.springframework.web.socket.adapter.standard; + +import org.springframework.lang.NonNullApi; diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/client/jetty/JettyWebSocketClient.java b/spring-websocket/src/main/java/org/springframework/web/socket/client/jetty/JettyWebSocketClient.java index 79e1807a55..f83f29f666 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/client/jetty/JettyWebSocketClient.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/client/jetty/JettyWebSocketClient.java @@ -32,6 +32,7 @@ import org.springframework.core.task.AsyncListenableTaskExecutor; import org.springframework.core.task.SimpleAsyncTaskExecutor; import org.springframework.core.task.TaskExecutor; import org.springframework.http.HttpHeaders; +import org.springframework.lang.Nullable; import org.springframework.util.concurrent.ListenableFuture; import org.springframework.util.concurrent.ListenableFutureTask; import org.springframework.web.socket.WebSocketExtension; @@ -89,7 +90,7 @@ public class JettyWebSocketClient extends AbstractWebSocketClient implements Lif * *

      By default an instance of {@code SimpleAsyncTaskExecutor} is used. */ - public void setTaskExecutor(AsyncListenableTaskExecutor taskExecutor) { + public void setTaskExecutor(@Nullable AsyncListenableTaskExecutor taskExecutor) { this.taskExecutor = taskExecutor; } @@ -192,6 +193,7 @@ public class JettyWebSocketClient extends AbstractWebSocketClient implements Lif * @return the user to make available through {@link WebSocketSession#getPrincipal()}; * by default this method returns {@code null} */ + @Nullable protected Principal getUser() { return null; } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/client/jetty/package-info.java b/spring-websocket/src/main/java/org/springframework/web/socket/client/jetty/package-info.java index 04d236c6c5..6aeae7bd11 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/client/jetty/package-info.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/client/jetty/package-info.java @@ -1,4 +1,7 @@ /** * Client-side support for the Jetty WebSocket API. */ +@NonNullApi package org.springframework.web.socket.client.jetty; + +import org.springframework.lang.NonNullApi; diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/client/package-info.java b/spring-websocket/src/main/java/org/springframework/web/socket/client/package-info.java index c8cea9f47f..7c946ac395 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/client/package-info.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/client/package-info.java @@ -1,4 +1,7 @@ /** * Client-side abstractions for WebSocket applications. */ +@NonNullApi package org.springframework.web.socket.client; + +import org.springframework.lang.NonNullApi; diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/client/standard/StandardWebSocketClient.java b/spring-websocket/src/main/java/org/springframework/web/socket/client/standard/StandardWebSocketClient.java index 908097b747..0c40e883e1 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/client/standard/StandardWebSocketClient.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/client/standard/StandardWebSocketClient.java @@ -26,6 +26,7 @@ import java.util.List; import java.util.Locale; import java.util.Map; import java.util.concurrent.Callable; + import javax.websocket.ClientEndpointConfig; import javax.websocket.ClientEndpointConfig.Configurator; import javax.websocket.ContainerProvider; @@ -38,6 +39,7 @@ import org.springframework.core.task.AsyncListenableTaskExecutor; import org.springframework.core.task.SimpleAsyncTaskExecutor; import org.springframework.core.task.TaskExecutor; import org.springframework.http.HttpHeaders; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.concurrent.ListenableFuture; import org.springframework.util.concurrent.ListenableFutureTask; @@ -100,6 +102,7 @@ public class StandardWebSocketClient extends AbstractWebSocketClient { /** * The configured user properties, or {@code null}. */ + @Nullable public Map getUserProperties() { return this.userProperties; } @@ -110,7 +113,7 @@ public class StandardWebSocketClient extends AbstractWebSocketClient { * {@code doHandshake} methods will block until the connection is established. *

      By default, an instance of {@code SimpleAsyncTaskExecutor} is used. */ - public void setTaskExecutor(AsyncListenableTaskExecutor taskExecutor) { + public void setTaskExecutor(@Nullable AsyncListenableTaskExecutor taskExecutor) { this.taskExecutor = taskExecutor; } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/client/standard/package-info.java b/spring-websocket/src/main/java/org/springframework/web/socket/client/standard/package-info.java index 8682f9067b..90ceabc8bb 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/client/standard/package-info.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/client/standard/package-info.java @@ -1,4 +1,7 @@ /** * Client-side classes for use with standard Java WebSocket endpoints. */ +@NonNullApi package org.springframework.web.socket.client.standard; + +import org.springframework.lang.NonNullApi; diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/config/MessageBrokerBeanDefinitionParser.java b/spring-websocket/src/main/java/org/springframework/web/socket/config/MessageBrokerBeanDefinitionParser.java index 206d3dfb74..c1f9ef3e1e 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/config/MessageBrokerBeanDefinitionParser.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/config/MessageBrokerBeanDefinitionParser.java @@ -38,6 +38,7 @@ import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.beans.factory.xml.BeanDefinitionParser; import org.springframework.beans.factory.xml.ParserContext; import org.springframework.http.converter.json.Jackson2ObjectMapperFactoryBean; +import org.springframework.lang.Nullable; import org.springframework.messaging.converter.ByteArrayMessageConverter; import org.springframework.messaging.converter.CompositeMessageConverter; import org.springframework.messaging.converter.DefaultContentTypeResolver; @@ -260,6 +261,7 @@ class MessageBrokerBeanDefinitionParser implements BeanDefinitionParser { return new RuntimeBeanReference(name); } + @Nullable private RootBeanDefinition getDefaultExecutorBeanDefinition(String channelName) { if (channelName.equals("brokerChannel")) { return null; @@ -545,6 +547,7 @@ class MessageBrokerBeanDefinitionParser implements BeanDefinitionParser { registerBeanDef(beanDef, context, source); } + @Nullable private RuntimeBeanReference getValidator(Element messageBrokerElement, Object source, ParserContext parserContext) { if (messageBrokerElement.hasAttribute("validator")) { return new RuntimeBeanReference(messageBrokerElement.getAttribute("validator")); diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/config/WebSocketMessageBrokerStats.java b/spring-websocket/src/main/java/org/springframework/web/socket/config/WebSocketMessageBrokerStats.java index 0f5bd934e8..a18318cfca 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/config/WebSocketMessageBrokerStats.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/config/WebSocketMessageBrokerStats.java @@ -25,6 +25,7 @@ import java.util.concurrent.TimeUnit; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.lang.Nullable; import org.springframework.messaging.simp.stomp.StompBrokerRelayMessageHandler; import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; @@ -75,6 +76,7 @@ public class WebSocketMessageBrokerStats { this.stompSubProtocolHandler = initStompSubProtocolHandler(); } + @Nullable private StompSubProtocolHandler initStompSubProtocolHandler() { for (SubProtocolHandler handler : this.webSocketHandler.getProtocolHandlers()) { if (handler instanceof StompSubProtocolHandler) { @@ -105,6 +107,7 @@ public class WebSocketMessageBrokerStats { this.loggingTask = initLoggingTask(1 * 60 * 1000); } + @Nullable private ScheduledFuture initLoggingTask(long initialDelay) { if (logger.isInfoEnabled() && this.loggingPeriod > 0) { return this.sockJsTaskScheduler.scheduleAtFixedRate(new Runnable() { diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/config/WebSocketNamespaceUtils.java b/spring-websocket/src/main/java/org/springframework/web/socket/config/WebSocketNamespaceUtils.java index 4a07250fd9..52b85fc053 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/config/WebSocketNamespaceUtils.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/config/WebSocketNamespaceUtils.java @@ -27,6 +27,7 @@ import org.springframework.beans.factory.parsing.BeanComponentDefinition; import org.springframework.beans.factory.support.ManagedList; import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.beans.factory.xml.ParserContext; +import org.springframework.lang.Nullable; import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; import org.springframework.util.StringUtils; import org.springframework.util.xml.DomUtils; @@ -61,6 +62,7 @@ class WebSocketNamespaceUtils { return handlerRef; } + @Nullable public static RuntimeBeanReference registerSockJsService(Element element, String schedulerName, ParserContext context, Object source) { diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/AbstractWebSocketHandlerRegistration.java b/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/AbstractWebSocketHandlerRegistration.java index 83c5652a53..254b9445b7 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/AbstractWebSocketHandlerRegistration.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/AbstractWebSocketHandlerRegistration.java @@ -20,6 +20,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import org.springframework.lang.Nullable; import org.springframework.scheduling.TaskScheduler; import org.springframework.util.Assert; import org.springframework.util.LinkedMultiValueMap; @@ -140,6 +141,7 @@ public abstract class AbstractWebSocketHandlerRegistration implements WebSock * if the application did not provide one. This should be done prior to * calling {@link #getMappings()}. */ + @Nullable protected SockJsServiceRegistration getSockJsServiceRegistration() { return this.sockJsServiceRegistration; } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/WebMvcStompEndpointRegistry.java b/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/WebMvcStompEndpointRegistry.java index d3cb5b1a8e..781b7c7b09 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/WebMvcStompEndpointRegistry.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/WebMvcStompEndpointRegistry.java @@ -22,6 +22,7 @@ import java.util.List; import java.util.Map; import org.springframework.context.ApplicationContext; +import org.springframework.lang.Nullable; import org.springframework.scheduling.TaskScheduler; import org.springframework.util.Assert; import org.springframework.util.MultiValueMap; @@ -146,6 +147,7 @@ public class WebMvcStompEndpointRegistry implements StompEndpointRegistry { * Return a handler mapping with the mapped ViewControllers; or {@code null} * in case of no registrations. */ + @Nullable public AbstractHandlerMapping getHandlerMapping() { Map urlMap = new LinkedHashMap<>(); for (WebMvcStompWebSocketEndpointRegistration registration : this.registrations) { diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/package-info.java b/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/package-info.java index 806ea6812d..bf6f75ff81 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/package-info.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/package-info.java @@ -1,4 +1,7 @@ /** * Support for annotation-based WebSocket setup in configuration classes. */ +@NonNullApi package org.springframework.web.socket.config.annotation; + +import org.springframework.lang.NonNullApi; diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/config/package-info.java b/spring-websocket/src/main/java/org/springframework/web/socket/config/package-info.java index cc601c99a0..aa058da84d 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/config/package-info.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/config/package-info.java @@ -1,4 +1,7 @@ /** * Configuration support for WebSocket request handling. */ +@NonNullApi package org.springframework.web.socket.config; + +import org.springframework.lang.NonNullApi; diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/handler/package-info.java b/spring-websocket/src/main/java/org/springframework/web/socket/handler/package-info.java index 329f2d4df3..59c0a5f1c6 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/handler/package-info.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/handler/package-info.java @@ -2,4 +2,7 @@ * Convenient {@link org.springframework.web.socket.WebSocketHandler} * implementations and decorators. */ +@NonNullApi package org.springframework.web.socket.handler; + +import org.springframework.lang.NonNullApi; diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/messaging/StompSubProtocolHandler.java b/spring-websocket/src/main/java/org/springframework/web/socket/messaging/StompSubProtocolHandler.java index 326371b3c5..2d52027b26 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/messaging/StompSubProtocolHandler.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/messaging/StompSubProtocolHandler.java @@ -32,6 +32,7 @@ import org.apache.commons.logging.LogFactory; import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.ApplicationEventPublisherAware; +import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.simp.SimpAttributes; @@ -531,6 +532,7 @@ public class StompSubProtocolHandler implements SubProtocolHandler, ApplicationE return connectedHeaders; } + @Nullable private String getDisconnectReceipt(SimpMessageHeaderAccessor simpHeaders) { String name = StompHeaderAccessor.DISCONNECT_MESSAGE_HEADER; Message message = (Message) simpHeaders.getHeader(name); diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/messaging/SubProtocolErrorHandler.java b/spring-websocket/src/main/java/org/springframework/web/socket/messaging/SubProtocolErrorHandler.java index 55fa13c505..a9a0b8e635 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/messaging/SubProtocolErrorHandler.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/messaging/SubProtocolErrorHandler.java @@ -16,6 +16,7 @@ package org.springframework.web.socket.messaging; +import org.springframework.lang.Nullable; import org.springframework.messaging.Message; /** @@ -39,7 +40,8 @@ public interface SubProtocolErrorHandler

      { * @return the error message to send to the client, or {@code null} in which * case no message will be sent. */ - Message

      handleClientMessageProcessingError(Message

      clientMessage, Throwable ex); + @Nullable + Message

      handleClientMessageProcessingError(@Nullable Message

      clientMessage, Throwable ex); /** * Handle errors sent from the server side to clients, e.g. errors from the @@ -50,6 +52,7 @@ public interface SubProtocolErrorHandler

      { * @return the error message to send to the client, or {@code null} in which * case no message will be sent. */ + @Nullable Message

      handleErrorMessageToClient(Message

      errorMessage); } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/messaging/SubProtocolHandler.java b/spring-websocket/src/main/java/org/springframework/web/socket/messaging/SubProtocolHandler.java index 1324a40878..5c51bf6479 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/messaging/SubProtocolHandler.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/messaging/SubProtocolHandler.java @@ -18,6 +18,7 @@ package org.springframework.web.socket.messaging; import java.util.List; +import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.web.socket.CloseStatus; @@ -67,6 +68,7 @@ public interface SubProtocolHandler { * Resolve the session id from the given message or return {@code null}. * @param message the message to resolve the session id from */ + @Nullable String resolveSessionId(Message message); /** diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/messaging/package-info.java b/spring-websocket/src/main/java/org/springframework/web/socket/messaging/package-info.java index 4bb6b141c4..32c4674904 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/messaging/package-info.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/messaging/package-info.java @@ -1,4 +1,7 @@ /** * WebSocket integration for Spring's messaging module. */ +@NonNullApi package org.springframework.web.socket.messaging; + +import org.springframework.lang.NonNullApi; diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/package-info.java b/spring-websocket/src/main/java/org/springframework/web/socket/package-info.java index 2b723940e4..43f91f240a 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/package-info.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/package-info.java @@ -1,4 +1,7 @@ /** * Common abstractions and Spring configuration support for WebSocket applications. */ +@NonNullApi package org.springframework.web.socket; + +import org.springframework.lang.NonNullApi; diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/server/RequestUpgradeStrategy.java b/spring-websocket/src/main/java/org/springframework/web/socket/server/RequestUpgradeStrategy.java index 4d05f1eb72..f0d308334f 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/server/RequestUpgradeStrategy.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/server/RequestUpgradeStrategy.java @@ -22,6 +22,7 @@ import java.util.Map; import org.springframework.http.server.ServerHttpRequest; import org.springframework.http.server.ServerHttpResponse; +import org.springframework.lang.Nullable; import org.springframework.web.socket.WebSocketExtension; import org.springframework.web.socket.WebSocketHandler; @@ -61,7 +62,7 @@ public interface RequestUpgradeStrategy { * handshake request. */ void upgrade(ServerHttpRequest request, ServerHttpResponse response, - String selectedProtocol, List selectedExtensions, Principal user, + @Nullable String selectedProtocol, List selectedExtensions, Principal user, WebSocketHandler wsHandler, Map attributes) throws HandshakeFailureException; } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/server/package-info.java b/spring-websocket/src/main/java/org/springframework/web/socket/server/package-info.java index c3b8df4a89..661a229943 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/server/package-info.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/server/package-info.java @@ -1,4 +1,7 @@ /** * Server-side abstractions for WebSocket interactions. */ +@NonNullApi package org.springframework.web.socket.server; + +import org.springframework.lang.NonNullApi; diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/server/standard/package-info.java b/spring-websocket/src/main/java/org/springframework/web/socket/server/standard/package-info.java index a7e557c348..c3a89fe2b5 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/server/standard/package-info.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/server/standard/package-info.java @@ -1,4 +1,7 @@ /** * Server-side classes for use with standard JSR-356 WebSocket endpoints. */ +@NonNullApi package org.springframework.web.socket.server.standard; + +import org.springframework.lang.NonNullApi; diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/server/support/AbstractHandshakeHandler.java b/spring-websocket/src/main/java/org/springframework/web/socket/server/support/AbstractHandshakeHandler.java index 9cdd836e8a..2515327f5a 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/server/support/AbstractHandshakeHandler.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/server/support/AbstractHandshakeHandler.java @@ -33,6 +33,7 @@ import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; import org.springframework.http.server.ServerHttpRequest; import org.springframework.http.server.ServerHttpResponse; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.ReflectionUtils; @@ -340,6 +341,7 @@ public abstract class AbstractHandshakeHandler implements HandshakeHandler, Life * @return the selected protocols or {@code null} * @see #determineHandlerSupportedProtocols(WebSocketHandler) */ + @Nullable protected String selectProtocol(List requestedProtocols, WebSocketHandler webSocketHandler) { if (requestedProtocols != null) { List handlerProtocols = determineHandlerSupportedProtocols(webSocketHandler); @@ -402,6 +404,7 @@ public abstract class AbstractHandshakeHandler implements HandshakeHandler, Life * @param attributes handshake attributes to pass to the WebSocket session * @return the user for the WebSocket session, or {@code null} if not available */ + @Nullable protected Principal determineUser(ServerHttpRequest request, WebSocketHandler wsHandler, Map attributes) { diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/server/support/HttpSessionHandshakeInterceptor.java b/spring-websocket/src/main/java/org/springframework/web/socket/server/support/HttpSessionHandshakeInterceptor.java index 57f9cd0d73..9f6142e336 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/server/support/HttpSessionHandshakeInterceptor.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/server/support/HttpSessionHandshakeInterceptor.java @@ -25,6 +25,7 @@ import javax.servlet.http.HttpSession; import org.springframework.http.server.ServerHttpRequest; import org.springframework.http.server.ServerHttpResponse; import org.springframework.http.server.ServletServerHttpRequest; +import org.springframework.lang.Nullable; import org.springframework.web.socket.WebSocketHandler; import org.springframework.web.socket.WebSocketSession; import org.springframework.web.socket.server.HandshakeInterceptor; @@ -160,6 +161,7 @@ public class HttpSessionHandshakeInterceptor implements HandshakeInterceptor { return true; } + @Nullable private HttpSession getSession(ServerHttpRequest request) { if (request instanceof ServletServerHttpRequest) { ServletServerHttpRequest serverRequest = (ServletServerHttpRequest) request; diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/server/support/package-info.java b/spring-websocket/src/main/java/org/springframework/web/socket/server/support/package-info.java index 33b4aec183..571d87ca51 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/server/support/package-info.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/server/support/package-info.java @@ -2,4 +2,7 @@ * Server-side support classes including container-specific strategies * for upgrading a request. */ +@NonNullApi package org.springframework.web.socket.server.support; + +import org.springframework.lang.NonNullApi; diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/SockJsClient.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/SockJsClient.java index 47cebcac3b..8060e8b169 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/SockJsClient.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/SockJsClient.java @@ -30,6 +30,7 @@ import org.apache.commons.logging.LogFactory; import org.springframework.context.Lifecycle; import org.springframework.http.HttpHeaders; +import org.springframework.lang.Nullable; import org.springframework.scheduling.TaskScheduler; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; @@ -323,6 +324,7 @@ public class SockJsClient implements WebSocketClient, Lifecycle { *

      By default this method returns {@code null}. * @return the user to associate with the session (possibly {@code null}) */ + @Nullable protected Principal getUser() { return null; } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/TransportRequest.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/TransportRequest.java index bb378bde20..a139903482 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/TransportRequest.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/TransportRequest.java @@ -20,6 +20,7 @@ import java.net.URI; import java.security.Principal; import org.springframework.http.HttpHeaders; +import org.springframework.lang.Nullable; import org.springframework.web.socket.sockjs.frame.SockJsMessageCodec; /** @@ -62,6 +63,7 @@ public interface TransportRequest { /** * Return the user associated with the request, if any. */ + @Nullable Principal getUser(); /** diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/package-info.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/package-info.java index ce5ad42edd..b47686b0ed 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/package-info.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/package-info.java @@ -2,4 +2,7 @@ * SockJS client implementation of * {@link org.springframework.web.socket.client.WebSocketClient}. */ +@NonNullApi package org.springframework.web.socket.sockjs.client; + +import org.springframework.lang.NonNullApi; diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/frame/SockJsFrame.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/frame/SockJsFrame.java index 70e26db64c..22e4c30f7b 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/frame/SockJsFrame.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/frame/SockJsFrame.java @@ -19,6 +19,7 @@ package org.springframework.web.socket.sockjs.frame; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -104,6 +105,7 @@ public class SockJsFrame { * for SockJS "open" and "close" frames, which do not contain data, return * {@code null}. */ + @Nullable public String getFrameData() { if (getType() == SockJsFrameType.OPEN || getType() == SockJsFrameType.HEARTBEAT) { return null; diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/frame/SockJsMessageCodec.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/frame/SockJsMessageCodec.java index ce55b16980..d89cb2fa36 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/frame/SockJsMessageCodec.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/frame/SockJsMessageCodec.java @@ -19,6 +19,8 @@ package org.springframework.web.socket.sockjs.frame; import java.io.IOException; import java.io.InputStream; +import org.springframework.lang.Nullable; + /** * Encode and decode messages to and from a SockJS message frame, * essentially an array of JSON-encoded messages. For example: @@ -48,6 +50,7 @@ public interface SockJsMessageCodec { * @return an array of messages, or {@code null} if none * @throws IOException if the content could not be parsed */ + @Nullable String[] decode(String content) throws IOException; /** @@ -56,6 +59,7 @@ public interface SockJsMessageCodec { * @return an array of messages, or {@code null} if none * @throws IOException if the content could not be parsed */ + @Nullable String[] decodeInputStream(InputStream content) throws IOException; } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/frame/package-info.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/frame/package-info.java index c11a9fa88a..ed627794e7 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/frame/package-info.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/frame/package-info.java @@ -2,4 +2,7 @@ * Support classes for creating SockJS frames including the encoding and decoding * of SockJS message frames. */ +@NonNullApi package org.springframework.web.socket.sockjs.frame; + +import org.springframework.lang.NonNullApi; diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/package-info.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/package-info.java index 93674d7271..319738f50e 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/package-info.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/package-info.java @@ -1,4 +1,7 @@ /** * Top-level SockJS types. */ +@NonNullApi package org.springframework.web.socket.sockjs; + +import org.springframework.lang.NonNullApi; diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/support/package-info.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/support/package-info.java index 68b6ec394c..4bed57e4d6 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/support/package-info.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/support/package-info.java @@ -3,4 +3,7 @@ * {@link org.springframework.web.socket.sockjs.support.AbstractSockJsService} * implementation. */ +@NonNullApi package org.springframework.web.socket.sockjs.support; + +import org.springframework.lang.NonNullApi; diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/AbstractHttpSendingTransportHandler.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/AbstractHttpSendingTransportHandler.java index 87659d7c1f..43d6e5779f 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/AbstractHttpSendingTransportHandler.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/AbstractHttpSendingTransportHandler.java @@ -23,6 +23,7 @@ import java.util.regex.Pattern; import org.springframework.http.MediaType; import org.springframework.http.server.ServerHttpRequest; import org.springframework.http.server.ServerHttpResponse; +import org.springframework.lang.Nullable; import org.springframework.util.MultiValueMap; import org.springframework.util.StringUtils; import org.springframework.web.socket.WebSocketHandler; @@ -112,6 +113,7 @@ public abstract class AbstractHttpSendingTransportHandler extends AbstractTransp protected abstract SockJsFrameFormat getFrameFormat(ServerHttpRequest request); + @Nullable protected final String getCallbackParam(ServerHttpRequest request) { String query = request.getURI().getQuery(); MultiValueMap params = UriComponentsBuilder.newInstance().query(query).build().getQueryParams(); diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/package-info.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/package-info.java index 0dca99d930..4063304df4 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/package-info.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/package-info.java @@ -3,4 +3,7 @@ * implementation classes as well as a concrete * {@link org.springframework.web.socket.sockjs.SockJsService}. */ +@NonNullApi package org.springframework.web.socket.sockjs.transport.handler; + +import org.springframework.lang.NonNullApi; diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/package-info.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/package-info.java index be76b009da..75f1191564 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/package-info.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/package-info.java @@ -6,4 +6,7 @@ * counterparts for sending messages over the various transports, and * {@link org.springframework.web.socket.sockjs.transport.handler.DefaultSockJsService}. */ +@NonNullApi package org.springframework.web.socket.sockjs.transport; + +import org.springframework.lang.NonNullApi; diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/session/package-info.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/session/package-info.java index d35363ca1a..7aeb37495c 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/session/package-info.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/session/package-info.java @@ -2,4 +2,7 @@ * SockJS specific implementations of * {@link org.springframework.web.socket.WebSocketSession}. */ +@NonNullApi package org.springframework.web.socket.sockjs.transport.session; + +import org.springframework.lang.NonNullApi;